{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2019年11月自行车业务分析报告\n",
    "**目录：**\n",
    "- **一、自行车整体销售表现**\n",
    "- **二、2019年11月自行车地域销售表现**\n",
    "- **三、2019年11月自行车产品销售表现**\n",
    "- **四、用户行为分析**\n",
    "- **五、2019年11月热品销售分析**\n",
    "\n",
    "**计算结果存入数据库_对应表名：**\n",
    "\n",
    "- 自行车整体销售表现:pt_overall_sale_performance_1\n",
    "- 2019年11月自行车地域销售表现:pt_bicy_november_territory_2、pt_bicy_november_october_city_3\n",
    "- 2019年11月自行车产品销售表现：pt_bicycle_product_sales_month_4、pt_bicycle_product_sales_order_month_4、pt_bicycle_product_sales_order_month_11\n",
    "- 用户行为分析：pt_user_behavior_november\n",
    "- 2019年11月热品销售分析：pt_hot_products_november"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一、自行车整体销售表现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1、从数据库读取源数据：dw_customer_order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入模块\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pymysql\n",
    "from pymysql import *\n",
    "pymysql.install_as_MySQLdb()\n",
    "from sqlalchemy.pool import QueuePool\n",
    "from sqlalchemy import create_engine\n",
    "\n",
    "#读取源数据。不同城市，每天产品销售信息\n",
    "#创建数据库引擎\n",
    "engine = create_engine('mysql://frogdata001:Frogdata!123@106.13.128.83:3306/adventure_ods?charset=gbk')\n",
    "datafrog=engine\n",
    "gather_customer_order=pd.read_sql_query(\"select * from dw_customer_order\",con = datafrog)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>AWC Logo Cap</td>\n",
       "      <td>帽子</td>\n",
       "      <td>服装</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>8.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>吉林省</td>\n",
       "      <td>长春市</td>\n",
       "      <td>东北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>AWC Logo Cap</td>\n",
       "      <td>帽子</td>\n",
       "      <td>服装</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>8.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>黑龙江省</td>\n",
       "      <td>伊春市</td>\n",
       "      <td>东北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>AWC Logo Cap</td>\n",
       "      <td>帽子</td>\n",
       "      <td>服装</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>8.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>蚌埠市</td>\n",
       "      <td>华东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>AWC Logo Cap</td>\n",
       "      <td>帽子</td>\n",
       "      <td>服装</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>8.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>南通市</td>\n",
       "      <td>华东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>AWC Logo Cap</td>\n",
       "      <td>帽子</td>\n",
       "      <td>服装</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>8.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>宿迁市</td>\n",
       "      <td>华东</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  create_date  product_name cpzl_zw cplb_zw  order_num  customer_num  \\\n",
       "0  2019-01-01  AWC Logo Cap      帽子      服装          1             1   \n",
       "1  2019-01-01  AWC Logo Cap      帽子      服装          1             1   \n",
       "2  2019-01-01  AWC Logo Cap      帽子      服装          1             1   \n",
       "3  2019-01-01  AWC Logo Cap      帽子      服装          1             1   \n",
       "4  2019-01-01  AWC Logo Cap      帽子      服装          1             1   \n",
       "\n",
       "   sum_amount is_current_year is_last_year is_yesterday is_today  \\\n",
       "0        8.99               0            1            0        0   \n",
       "1        8.99               0            1            0        0   \n",
       "2        8.99               0            1            0        0   \n",
       "3        8.99               0            1            0        0   \n",
       "4        8.99               0            1            0        0   \n",
       "\n",
       "  is_current_month is_current_quarter chinese_province chinese_city  \\\n",
       "0                0                  0              吉林省          长春市   \n",
       "1                0                  0             黑龙江省          伊春市   \n",
       "2                0                  0              安徽省          蚌埠市   \n",
       "3                0                  0              江苏省          南通市   \n",
       "4                0                  0              江苏省          宿迁市   \n",
       "\n",
       "  chinese_territory  \n",
       "0                东北  \n",
       "1                东北  \n",
       "2                华东  \n",
       "3                华东  \n",
       "4                华东  "
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "#查看源数据前5行，观察数据，判断数据是否正常识别\n",
    "gather_customer_order.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 203401 entries, 0 to 203400\n",
      "Data columns (total 16 columns):\n",
      "create_date           203401 non-null object\n",
      "product_name          203401 non-null object\n",
      "cpzl_zw               203401 non-null object\n",
      "cplb_zw               203401 non-null object\n",
      "order_num             203401 non-null int64\n",
      "customer_num          203401 non-null int64\n",
      "sum_amount            203401 non-null float64\n",
      "is_current_year       203401 non-null object\n",
      "is_last_year          203401 non-null object\n",
      "is_yesterday          203401 non-null object\n",
      "is_today              203401 non-null object\n",
      "is_current_month      203401 non-null object\n",
      "is_current_quarter    203401 non-null object\n",
      "chinese_province      203401 non-null object\n",
      "chinese_city          203401 non-null object\n",
      "chinese_territory     203401 non-null object\n",
      "dtypes: float64(1), int64(2), object(13)\n",
      "memory usage: 24.8+ MB\n"
     ]
    }
   ],
   "source": [
    "gather_customer_order.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "#增加create_year_month月份字段。按月维度分析时使用\n",
    "gather_customer_order['create_year_month']=gather_customer_order['create_date'].map(lambda x: 100*x.year + x.month)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         201901\n",
       "1         201901\n",
       "2         201901\n",
       "3         201901\n",
       "4         201901\n",
       "5         201901\n",
       "6         201901\n",
       "7         201901\n",
       "8         201901\n",
       "9         201901\n",
       "10        201901\n",
       "11        201901\n",
       "12        201901\n",
       "13        201901\n",
       "14        201901\n",
       "15        201901\n",
       "16        201901\n",
       "17        201901\n",
       "18        201901\n",
       "19        201901\n",
       "20        201901\n",
       "21        201901\n",
       "22        201901\n",
       "23        201901\n",
       "24        201901\n",
       "25        201901\n",
       "26        201901\n",
       "27        201901\n",
       "28        201901\n",
       "29        201901\n",
       "           ...  \n",
       "203371    202005\n",
       "203372    202005\n",
       "203373    202005\n",
       "203374    202005\n",
       "203375    202005\n",
       "203376    202005\n",
       "203377    202005\n",
       "203378    202005\n",
       "203379    202005\n",
       "203380    202005\n",
       "203381    202005\n",
       "203382    202005\n",
       "203383    202005\n",
       "203384    202005\n",
       "203385    202005\n",
       "203386    202005\n",
       "203387    202005\n",
       "203388    202005\n",
       "203389    202005\n",
       "203390    202005\n",
       "203391    202005\n",
       "203392    202005\n",
       "203393    202005\n",
       "203394    202005\n",
       "203395    202005\n",
       "203396    202005\n",
       "203397    202005\n",
       "203398    202005\n",
       "203399    202005\n",
       "203400    202005\n",
       "Name: create_year_month, Length: 203401, dtype: int64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gather_customer_order['create_year_month']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>马鞍山市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>西藏自治区</td>\n",
       "      <td>拉萨市</td>\n",
       "      <td>西南</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济南市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2049.0982</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>潍坊市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>镇江市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_date         product_name cpzl_zw cplb_zw  order_num  customer_num  \\\n",
       "150  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "151  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "152  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "153  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "154  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "\n",
       "     sum_amount is_current_year is_last_year is_yesterday is_today  \\\n",
       "150   3399.9900               0            1            0        0   \n",
       "151   3399.9900               0            1            0        0   \n",
       "152   2294.9900               0            1            0        0   \n",
       "153   2049.0982               0            1            0        0   \n",
       "154   2294.9900               0            1            0        0   \n",
       "\n",
       "    is_current_month is_current_quarter chinese_province chinese_city  \\\n",
       "150                0                  0              安徽省         马鞍山市   \n",
       "151                0                  0            西藏自治区          拉萨市   \n",
       "152                0                  0              山东省          济南市   \n",
       "153                0                  0              山东省          潍坊市   \n",
       "154                0                  0              江苏省          镇江市   \n",
       "\n",
       "    chinese_territory  create_year_month  \n",
       "150                华东             201901  \n",
       "151                西南             201901  \n",
       "152                华东             201901  \n",
       "153                华东             201901  \n",
       "154                华东             201901  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#筛选产品类别为自行车的数据\n",
    "gather_customer_order = gather_customer_order[gather_customer_order['cplb_zw']==\"自行车\"]\n",
    "gather_customer_order.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2、自行车整体销售量表现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "      <th>sum_amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>5.583114e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201902</td>\n",
       "      <td>2832</td>\n",
       "      <td>5.352128e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201903</td>\n",
       "      <td>3182</td>\n",
       "      <td>5.804733e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201904</td>\n",
       "      <td>2979</td>\n",
       "      <td>5.505983e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201905</td>\n",
       "      <td>3093</td>\n",
       "      <td>5.869147e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month  order_num    sum_amount\n",
       "0             201901       3036  5.583114e+06\n",
       "1             201902       2832  5.352128e+06\n",
       "2             201903       3182  5.804733e+06\n",
       "3             201904       2979  5.505983e+06\n",
       "4             201905       3093  5.869147e+06"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每月订单数量和销售金额，用groupby创建一个新的对象，需要将order_num、sum_amount求和\n",
    "overall_sales_performance = gather_customer_order.groupby(by='create_year_month').agg({\n",
    "    'order_num':sum,'sum_amount':sum}).reset_index()\n",
    "\n",
    "#按日期降序排序，方便计算环比\n",
    "overall_sales_performance.sort_values(by='create_year_month',ascending=False)\n",
    "\n",
    "overall_sales_performance.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.07203389830508475,\n",
       " -0.10999371464487744,\n",
       " 0.06814367237327962,\n",
       " -0.03685741998060136,\n",
       " 0.023155805491233875,\n",
       " -0.028911018310311596,\n",
       " 0.0103862382343395,\n",
       " 0.05549845837615622,\n",
       " -0.05717054263565891,\n",
       " -0.06634499396863691,\n",
       " 0.08224543080939947,\n",
       " -0.0316055625790139,\n",
       " -0.1766848816029144,\n",
       " -0.46025280898876403,\n",
       " 3.1857730746619635,\n",
       " -0.019596541786743516,\n",
       " 0]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求每月自行车销售订单量环比，观察最近一年数据变化趋势\n",
    "#环比是本月与上月的对比，例如本期2019-02月销售额与上一期2019-01月销售额做对比\n",
    "order_num_diff = list((overall_sales_performance.order_num.diff()/overall_sales_performance.order_num)/-1)\n",
    "order_num_diff.pop(0) #删除列表中第一个元素\n",
    "order_num_diff.append(0) #将0新增到列表末尾\n",
    "order_num_diff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>order_num_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>5.583114e+06</td>\n",
       "      <td>0.072034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201902</td>\n",
       "      <td>2832</td>\n",
       "      <td>5.352128e+06</td>\n",
       "      <td>-0.109994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201903</td>\n",
       "      <td>3182</td>\n",
       "      <td>5.804733e+06</td>\n",
       "      <td>0.068144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201904</td>\n",
       "      <td>2979</td>\n",
       "      <td>5.505983e+06</td>\n",
       "      <td>-0.036857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201905</td>\n",
       "      <td>3093</td>\n",
       "      <td>5.869147e+06</td>\n",
       "      <td>0.023156</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month  order_num    sum_amount  order_num_diff\n",
       "0             201901       3036  5.583114e+06        0.072034\n",
       "1             201902       2832  5.352128e+06       -0.109994\n",
       "2             201903       3182  5.804733e+06        0.068144\n",
       "3             201904       2979  5.505983e+06       -0.036857\n",
       "4             201905       3093  5.869147e+06        0.023156"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将环比转化为DataFrame  \n",
    "overall_sales_performance= pd.concat([overall_sales_performance,pd.DataFrame({'order_num_diff':order_num_diff})],axis=1)\n",
    "overall_sales_performance.head()  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>order_num_diff</th>\n",
       "      <th>sum_amount_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>5.583114e+06</td>\n",
       "      <td>0.072034</td>\n",
       "      <td>0.043158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201902</td>\n",
       "      <td>2832</td>\n",
       "      <td>5.352128e+06</td>\n",
       "      <td>-0.109994</td>\n",
       "      <td>-0.077972</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201903</td>\n",
       "      <td>3182</td>\n",
       "      <td>5.804733e+06</td>\n",
       "      <td>0.068144</td>\n",
       "      <td>0.054259</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201904</td>\n",
       "      <td>2979</td>\n",
       "      <td>5.505983e+06</td>\n",
       "      <td>-0.036857</td>\n",
       "      <td>-0.061877</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201905</td>\n",
       "      <td>3093</td>\n",
       "      <td>5.869147e+06</td>\n",
       "      <td>0.023156</td>\n",
       "      <td>0.019123</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month  order_num    sum_amount  order_num_diff  sum_amount_diff\n",
       "0             201901       3036  5.583114e+06        0.072034         0.043158\n",
       "1             201902       2832  5.352128e+06       -0.109994        -0.077972\n",
       "2             201903       3182  5.804733e+06        0.068144         0.054259\n",
       "3             201904       2979  5.505983e+06       -0.036857        -0.061877\n",
       "4             201905       3093  5.869147e+06        0.023156         0.019123"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求每月自行车销售金额环比\n",
    "sum_amount_diff = list((overall_sales_performance.sum_amount.diff()/overall_sales_performance.sum_amount)/-1)\n",
    "sum_amount_diff.pop(0) #删除列表中第一个元素\n",
    "sum_amount_diff.append(0) #将0新增到列表末尾\n",
    "sum_amount_diff\n",
    "\n",
    "#将环比转化为DataFrame\n",
    "#销量环比字段名order_diff，销售金额环比字段名amount_diff\n",
    "overall_sales_performance = pd.concat([overall_sales_performance,pd.DataFrame({'sum_amount_diff':sum_amount_diff})],axis=1)\n",
    "\n",
    "#销量环比字段名order_diff，销售金额环比字段名amount_diff\n",
    "overall_sales_performance.sort_values(by='create_year_month',ascending=True)\n",
    "\n",
    "#查看每月自行车订单量、销售金额、环比、前5行\n",
    "overall_sales_performance.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**字段注释：**\n",
    "\n",
    "create_year_month：时间，order_num：本月累计销售数量，sum_amount：本月累计销售金额，order_diff：本月销售数量环比，\n",
    "\n",
    "sum_amount_diff：本月销售金额环比，dw_customer_order:用户订单表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将数据存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/datafrog05_adventure?charset=gbk')\n",
    "# datafrog=engine\n",
    "# overall_sales_performance.to_sql('pt_overall_sale_performance_1',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "##  二、2019年11月自行车地域销售表现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1、源数据dw_customer_order，数据清洗筛选10月11月数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>马鞍山市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>西藏自治区</td>\n",
       "      <td>拉萨市</td>\n",
       "      <td>西南</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济南市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2049.0982</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>潍坊市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>镇江市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_date         product_name cpzl_zw cplb_zw  order_num  customer_num  \\\n",
       "150  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "151  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "152  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "153  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "154  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "\n",
       "     sum_amount is_current_year is_last_year is_yesterday is_today  \\\n",
       "150   3399.9900               0            1            0        0   \n",
       "151   3399.9900               0            1            0        0   \n",
       "152   2294.9900               0            1            0        0   \n",
       "153   2049.0982               0            1            0        0   \n",
       "154   2294.9900               0            1            0        0   \n",
       "\n",
       "    is_current_month is_current_quarter chinese_province chinese_city  \\\n",
       "150                0                  0              安徽省         马鞍山市   \n",
       "151                0                  0            西藏自治区          拉萨市   \n",
       "152                0                  0              山东省          济南市   \n",
       "153                0                  0              山东省          潍坊市   \n",
       "154                0                  0              江苏省          镇江市   \n",
       "\n",
       "    chinese_territory  create_year_month  \n",
       "150                华东             201901  \n",
       "151                西南             201901  \n",
       "152                华东             201901  \n",
       "153                华东             201901  \n",
       "154                华东             201901  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#gather_customer_order在分析自行车整体表现时已从数据库导入表（dw_customer_order），并筛选仅自行车数据，这里不再导入\n",
    "gather_customer_order.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6266"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#筛选10月11月自行车数据\n",
    "gather_customer_order_10_11 = gather_customer_order[gather_customer_order['create_year_month'].isin(['201910','201911'])]\n",
    "\n",
    "#10月11月自行车订单数据共6266条\n",
    "len(gather_customer_order_10_11)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2、2019年11月自行车区域销售量表现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "      <th>sum_amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东北</td>\n",
       "      <td>201910</td>\n",
       "      <td>274</td>\n",
       "      <td>5.211772e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>东北</td>\n",
       "      <td>201911</td>\n",
       "      <td>300</td>\n",
       "      <td>5.600535e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>华东</td>\n",
       "      <td>201910</td>\n",
       "      <td>871</td>\n",
       "      <td>1.597676e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>华东</td>\n",
       "      <td>201911</td>\n",
       "      <td>927</td>\n",
       "      <td>1.770426e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>华中</td>\n",
       "      <td>201910</td>\n",
       "      <td>511</td>\n",
       "      <td>9.594011e+05</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  chinese_territory  create_year_month  order_num    sum_amount\n",
       "0                东北             201910        274  5.211772e+05\n",
       "1                东北             201911        300  5.600535e+05\n",
       "2                华东             201910        871  1.597676e+06\n",
       "3                华东             201911        927  1.770426e+06\n",
       "4                华中             201910        511  9.594011e+05"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按照区域、月分组,订单量求和，销售金额求和\n",
    "gather_customer_order_10_11_group= gather_customer_order_10_11.groupby(['chinese_territory','create_year_month']).agg({'order_num':'sum','sum_amount':'sum'}).reset_index()\n",
    "\n",
    "gather_customer_order_10_11_group.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['东北', '华东', '华中', '华北', '华南', '台港澳', '西北', '西南']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将区域存为列表\n",
    "region_list=gather_customer_order_10_11_group['chinese_territory'].drop_duplicates(keep='first').values.tolist()\n",
    "\n",
    "region_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pct_change()当前元素与先前元素的相差百分比,求不同区域10月11月环比\n",
    "order_x = pd.Series([])\n",
    "amount_x = pd.Series([])\n",
    "for i in region_list:\n",
    "    a=gather_customer_order_10_11_group.loc[gather_customer_order_10_11_group['chinese_territory']==i]['order_num'].pct_change().fillna(0)\n",
    "    b=gather_customer_order_10_11_group.loc[gather_customer_order_10_11_group['chinese_territory']==i]['sum_amount'].pct_change().fillna(0)\n",
    "    order_x=order_x.append(a)\n",
    "    amount_x = amount_x.append(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>order_diff</th>\n",
       "      <th>amount_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东北</td>\n",
       "      <td>201910</td>\n",
       "      <td>274</td>\n",
       "      <td>5.211772e+05</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>东北</td>\n",
       "      <td>201911</td>\n",
       "      <td>300</td>\n",
       "      <td>5.600535e+05</td>\n",
       "      <td>0.094891</td>\n",
       "      <td>0.074593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>华东</td>\n",
       "      <td>201910</td>\n",
       "      <td>871</td>\n",
       "      <td>1.597676e+06</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>华东</td>\n",
       "      <td>201911</td>\n",
       "      <td>927</td>\n",
       "      <td>1.770426e+06</td>\n",
       "      <td>0.064294</td>\n",
       "      <td>0.108126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>华中</td>\n",
       "      <td>201910</td>\n",
       "      <td>511</td>\n",
       "      <td>9.594011e+05</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  chinese_territory  create_year_month  order_num    sum_amount  order_diff  \\\n",
       "0                东北             201910        274  5.211772e+05    0.000000   \n",
       "1                东北             201911        300  5.600535e+05    0.094891   \n",
       "2                华东             201910        871  1.597676e+06    0.000000   \n",
       "3                华东             201911        927  1.770426e+06    0.064294   \n",
       "4                华中             201910        511  9.594011e+05    0.000000   \n",
       "\n",
       "   amount_diff  \n",
       "0     0.000000  \n",
       "1     0.074593  \n",
       "2     0.000000  \n",
       "3     0.108126  \n",
       "4     0.000000  "
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gather_customer_order_10_11_group['order_diff']=order_x\n",
    "gather_customer_order_10_11_group['amount_diff']=amount_x\n",
    "\n",
    "#10月11月各个区域自行车销售数量、销售金额环比\n",
    "gather_customer_order_10_11_group.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**字段注释：**\n",
    "\n",
    "chinese_territory：区域，create_year_month：时间，order_num：区域销售数量，sum_amount：区域销售金额，order_diff：本月销售数量环比，\n",
    "\n",
    "amount_diff：本月销售金额环比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将数据存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/adventure_ods?charset=gbk')\n",
    "# datafrog=engine\n",
    "# gather_customer_order_10_11_group.to_sql('pt_bicy_november_territory_2',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  2.3、2019年11月自行车销售量TOP10城市环比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>order_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>北京市</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>上海市</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>广州市</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>208</th>\n",
       "      <td>郑州市</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>常德市</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    chinese_city  order_num\n",
       "32           北京市         76\n",
       "3            上海市         65\n",
       "85           广州市         43\n",
       "208          郑州市         43\n",
       "81           常德市         39"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#筛选11月自行车交易数据\n",
    "gather_customer_order_11 = gather_customer_order_10_11.loc[gather_customer_order_10_11['create_year_month'] == 201911]\n",
    "\n",
    "# 按照chinese_city城市分组，求和销售数量order_num\n",
    "gather_customer_order_city_11= gather_customer_order_11.groupby(by='chinese_city').agg({'order_num':'sum'}).reset_index()\n",
    "\n",
    "# 11月自行车销售数量前十城市\n",
    "gather_customer_order_city_head=gather_customer_order_city_11.sort_values(by='order_num',ascending=False).head(10)\n",
    "gather_customer_order_city_head.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>103559</th>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2049.0982</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>直辖市</td>\n",
       "      <td>上海市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103566</th>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>直辖市</td>\n",
       "      <td>北京市</td>\n",
       "      <td>华北</td>\n",
       "      <td>201910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103579</th>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2319.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "      <td>华南</td>\n",
       "      <td>201910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103643</th>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3578.2700</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>湖北省</td>\n",
       "      <td>武汉市</td>\n",
       "      <td>华中</td>\n",
       "      <td>201910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103647</th>\n",
       "      <td>2019-10-01</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2181.5625</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>直辖市</td>\n",
       "      <td>上海市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201910</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       create_date         product_name cpzl_zw cplb_zw  order_num  \\\n",
       "103559  2019-10-01   Mountain-200 Black   山地自行车     自行车          1   \n",
       "103566  2019-10-01   Mountain-200 Black   山地自行车     自行车          1   \n",
       "103579  2019-10-01  Mountain-200 Silver   山地自行车     自行车          1   \n",
       "103643  2019-10-01         Road-150 Red   公路自行车     自行车          1   \n",
       "103647  2019-10-01       Road-250 Black   公路自行车     自行车          1   \n",
       "\n",
       "        customer_num  sum_amount is_current_year is_last_year is_yesterday  \\\n",
       "103559             1   2049.0982               0            1            0   \n",
       "103566             1   2294.9900               0            1            0   \n",
       "103579             1   2319.9900               0            1            0   \n",
       "103643             1   3578.2700               0            1            0   \n",
       "103647             1   2181.5625               0            1            0   \n",
       "\n",
       "       is_today is_current_month is_current_quarter chinese_province  \\\n",
       "103559        0                0                  0              直辖市   \n",
       "103566        0                0                  0              直辖市   \n",
       "103579        0                0                  0              广东省   \n",
       "103643        0                0                  0              湖北省   \n",
       "103647        0                0                  0              直辖市   \n",
       "\n",
       "       chinese_city chinese_territory  create_year_month  \n",
       "103559          上海市                华东             201910  \n",
       "103566          北京市                华北             201910  \n",
       "103579          广州市                华南             201910  \n",
       "103643          武汉市                华中             201910  \n",
       "103647          上海市                华东             201910  "
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#筛选销售前十城市，10月11月自行车销售数据\n",
    "\n",
    "gather_customer_order_10_11_head = gather_customer_order_10_11[gather_customer_order_10_11['chinese_city'].isin(list(gather_customer_order_city_head['chinese_city']))]\n",
    "gather_customer_order_10_11_head.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "      <th>sum_amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>上海市</td>\n",
       "      <td>201910</td>\n",
       "      <td>71</td>\n",
       "      <td>125669.7731</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海市</td>\n",
       "      <td>201911</td>\n",
       "      <td>65</td>\n",
       "      <td>111784.9069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>北京市</td>\n",
       "      <td>201910</td>\n",
       "      <td>60</td>\n",
       "      <td>91054.1623</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>北京市</td>\n",
       "      <td>201911</td>\n",
       "      <td>76</td>\n",
       "      <td>144640.7839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南京市</td>\n",
       "      <td>201910</td>\n",
       "      <td>36</td>\n",
       "      <td>59516.1606</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  chinese_city  create_year_month  order_num   sum_amount\n",
       "0          上海市             201910         71  125669.7731\n",
       "1          上海市             201911         65  111784.9069\n",
       "2          北京市             201910         60   91054.1623\n",
       "3          北京市             201911         76  144640.7839\n",
       "4          南京市             201910         36   59516.1606"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#分组计算前十城市，自行车销售数量销售金额\n",
    "gather_customer_order_city_10_11 = gather_customer_order_10_11_head.groupby(['chinese_city','create_year_month']).agg({'order_num':'sum','sum_amount':'sum'}).reset_index()\n",
    "gather_customer_order_city_10_11.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>order_diff</th>\n",
       "      <th>amount_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>上海市</td>\n",
       "      <td>201910</td>\n",
       "      <td>71</td>\n",
       "      <td>125669.7731</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>上海市</td>\n",
       "      <td>201911</td>\n",
       "      <td>65</td>\n",
       "      <td>111784.9069</td>\n",
       "      <td>-0.084507</td>\n",
       "      <td>-0.084507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>北京市</td>\n",
       "      <td>201910</td>\n",
       "      <td>60</td>\n",
       "      <td>91054.1623</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>北京市</td>\n",
       "      <td>201911</td>\n",
       "      <td>76</td>\n",
       "      <td>144640.7839</td>\n",
       "      <td>0.266667</td>\n",
       "      <td>0.266667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南京市</td>\n",
       "      <td>201910</td>\n",
       "      <td>36</td>\n",
       "      <td>59516.1606</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  chinese_city  create_year_month  order_num   sum_amount  order_diff  \\\n",
       "0          上海市             201910         71  125669.7731    0.000000   \n",
       "1          上海市             201911         65  111784.9069   -0.084507   \n",
       "2          北京市             201910         60   91054.1623    0.000000   \n",
       "3          北京市             201911         76  144640.7839    0.266667   \n",
       "4          南京市             201910         36   59516.1606    0.000000   \n",
       "\n",
       "   amount_diff  \n",
       "0     0.000000  \n",
       "1    -0.084507  \n",
       "2     0.000000  \n",
       "3     0.266667  \n",
       "4     0.000000  "
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算前十城市环比\n",
    "city_top_list =list(gather_customer_order_city_head['chinese_city']) \n",
    "order_top_x = pd.Series([])\n",
    "amount_top_x = pd.Series([])\n",
    "for i in city_top_list:\n",
    "    #print(i)\n",
    "    a=gather_customer_order_city_10_11.loc[gather_customer_order_city_10_11['chinese_city']==i]['order_num'].pct_change().fillna(0)\n",
    "    b=gather_customer_order_city_10_11.loc[gather_customer_order_city_10_11['chinese_city']==i]['order_num'].pct_change().fillna(0)\n",
    "    order_top_x=order_top_x.append(a)\n",
    "    amount_top_x =amount_top_x.append(b)\n",
    "    \n",
    "#order_diff销售数量环比，amount_diff销售金额环比\n",
    "gather_customer_order_city_10_11['order_diff']=order_top_x\n",
    "gather_customer_order_city_10_11['amount_diff']=amount_top_x\n",
    "\n",
    "gather_customer_order_city_10_11.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**字段注释**\n",
    "\n",
    "chinese_city：城市，create_year_month：时间，order_num：本月销售数量，sum_amount：本月销售金额，order_diff：本月销售数量环比，\n",
    "\n",
    "amount_diff：本月销售金额环比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [],
   "source": [
    "#存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/adventure_ods?charset=gbk')\n",
    "# datafrog=engine\n",
    "# gather_customer_order_city_10_11.to_sql('pt_bicy_november_october_city_3',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三、2019年11月自行车产品销售表现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1、数据源 dw_customer_order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>马鞍山市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>西藏自治区</td>\n",
       "      <td>拉萨市</td>\n",
       "      <td>西南</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济南市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_date         product_name cpzl_zw cplb_zw  order_num  customer_num  \\\n",
       "150  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "151  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "152  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "\n",
       "     sum_amount is_current_year is_last_year is_yesterday is_today  \\\n",
       "150     3399.99               0            1            0        0   \n",
       "151     3399.99               0            1            0        0   \n",
       "152     2294.99               0            1            0        0   \n",
       "\n",
       "    is_current_month is_current_quarter chinese_province chinese_city  \\\n",
       "150                0                  0              安徽省         马鞍山市   \n",
       "151                0                  0            西藏自治区          拉萨市   \n",
       "152                0                  0              山东省          济南市   \n",
       "\n",
       "    chinese_territory  create_year_month  \n",
       "150                华东             201901  \n",
       "151                西南             201901  \n",
       "152                华东             201901  "
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#gather_customer_order在分析自行车整体表现得时已从数据库导入表（ dw_customer_order），并筛选仅自行车数据，这里不再导入\n",
    "#查看数据源\n",
    "gather_customer_order.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2、细分市场销量表现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201902</td>\n",
       "      <td>2832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201903</td>\n",
       "      <td>3182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201904</td>\n",
       "      <td>2979</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201905</td>\n",
       "      <td>3093</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month  order_num\n",
       "0             201901       3036\n",
       "1             201902       2832\n",
       "2             201903       3182\n",
       "3             201904       2979\n",
       "4             201905       3093"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求每个月自行车累计销售数量\n",
    "gather_customer_order_group_month = gather_customer_order.groupby(['create_year_month']).agg({'order_num':'sum'}).reset_index()\n",
    "\n",
    "gather_customer_order_group_month.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num_x</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>马鞍山市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>西藏自治区</td>\n",
       "      <td>拉萨市</td>\n",
       "      <td>西南</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济南市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2049.0982</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>潍坊市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>镇江市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  create_date         product_name cpzl_zw cplb_zw  order_num_x  customer_num  \\\n",
       "0  2019-01-01  Mountain-100 Silver   山地自行车     自行车            1             1   \n",
       "1  2019-01-01  Mountain-100 Silver   山地自行车     自行车            1             1   \n",
       "2  2019-01-01   Mountain-200 Black   山地自行车     自行车            1             1   \n",
       "3  2019-01-01   Mountain-200 Black   山地自行车     自行车            1             1   \n",
       "4  2019-01-01   Mountain-200 Black   山地自行车     自行车            1             1   \n",
       "\n",
       "   sum_amount is_current_year is_last_year is_yesterday is_today  \\\n",
       "0   3399.9900               0            1            0        0   \n",
       "1   3399.9900               0            1            0        0   \n",
       "2   2294.9900               0            1            0        0   \n",
       "3   2049.0982               0            1            0        0   \n",
       "4   2294.9900               0            1            0        0   \n",
       "\n",
       "  is_current_month is_current_quarter chinese_province chinese_city  \\\n",
       "0                0                  0              安徽省         马鞍山市   \n",
       "1                0                  0            西藏自治区          拉萨市   \n",
       "2                0                  0              山东省          济南市   \n",
       "3                0                  0              山东省          潍坊市   \n",
       "4                0                  0              江苏省          镇江市   \n",
       "\n",
       "  chinese_territory  create_year_month  order_num_y  \n",
       "0                华东             201901         3036  \n",
       "1                西南             201901         3036  \n",
       "2                华东             201901         3036  \n",
       "3                华东             201901         3036  \n",
       "4                华东             201901         3036  "
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合并自行车销售信息表+自行车每月累计销售数量表，pd.merge\n",
    "order_num_proportion = pd.merge(gather_customer_order,gather_customer_order_group_month,on='create_year_month')\n",
    "order_num_proportion.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [],
   "source": [
    "#计算自行车销量/自行车每月销量占比\n",
    "order_num_proportion['order_proportion'] = order_num_proportion['order_num_x']/order_num_proportion['order_num_y']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num_x</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>sum_month_order</th>\n",
       "      <th>order_proportion</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>马鞍山市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>0.000329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>西藏自治区</td>\n",
       "      <td>拉萨市</td>\n",
       "      <td>西南</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>0.000329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济南市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>0.000329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2049.0982</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>潍坊市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>0.000329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>江苏省</td>\n",
       "      <td>镇江市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "      <td>3036</td>\n",
       "      <td>0.000329</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  create_date         product_name cpzl_zw cplb_zw  order_num_x  customer_num  \\\n",
       "0  2019-01-01  Mountain-100 Silver   山地自行车     自行车            1             1   \n",
       "1  2019-01-01  Mountain-100 Silver   山地自行车     自行车            1             1   \n",
       "2  2019-01-01   Mountain-200 Black   山地自行车     自行车            1             1   \n",
       "3  2019-01-01   Mountain-200 Black   山地自行车     自行车            1             1   \n",
       "4  2019-01-01   Mountain-200 Black   山地自行车     自行车            1             1   \n",
       "\n",
       "   sum_amount is_current_year is_last_year is_yesterday is_today  \\\n",
       "0   3399.9900               0            1            0        0   \n",
       "1   3399.9900               0            1            0        0   \n",
       "2   2294.9900               0            1            0        0   \n",
       "3   2049.0982               0            1            0        0   \n",
       "4   2294.9900               0            1            0        0   \n",
       "\n",
       "  is_current_month is_current_quarter chinese_province chinese_city  \\\n",
       "0                0                  0              安徽省         马鞍山市   \n",
       "1                0                  0            西藏自治区          拉萨市   \n",
       "2                0                  0              山东省          济南市   \n",
       "3                0                  0              山东省          潍坊市   \n",
       "4                0                  0              江苏省          镇江市   \n",
       "\n",
       "  chinese_territory  create_year_month  sum_month_order  order_proportion  \n",
       "0                华东             201901             3036          0.000329  \n",
       "1                西南             201901             3036          0.000329  \n",
       "2                华东             201901             3036          0.000329  \n",
       "3                华东             201901             3036          0.000329  \n",
       "4                华东             201901             3036          0.000329  "
      ]
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#重命名sum_month_order：自行车每月销售量\n",
    "order_num_proportion = order_num_proportion.rename(columns={'order_num_y':'sum_month_order'})\n",
    "\n",
    "order_num_proportion.head()                                                                                                   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**字段注释**\n",
    "\n",
    "create_date:时间, product_name：产品名, cpzl_zw：产品类别, cplb_zw：产品大类, order_num_x：产品当天销售数量,customer_num：当天用户购买人数,\n",
    "    \n",
    "sum_amount：产品当天销售金额, chinese_province:省份, chinese_city：城市, chinese_territory：区域,create_year_month：月份,\n",
    "    \n",
    "sum_month_order：本月累计销量, order_proportion：产品销量占比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #将每月自行车销售信息存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/adventure_ods?charset=gbk')\n",
    "# datafrog=engine\n",
    "# order_num_proportion.to_sql('pt_bicycle_product_sales_month_4',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3、公路/山地/旅游自行车细分市场表现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "150    山地自行车\n",
       "228    公路自行车\n",
       "343    旅游自行车\n",
       "Name: cpzl_zw, dtype: object"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查看自行车有那些产品子类\n",
    "gather_customer_order['cpzl_zw'].drop_duplicates()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**公路自行车细分市场销量表现**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [],
   "source": [
    "gather_customer_order_road = gather_customer_order[gather_customer_order['cpzl_zw'] == '公路自行车']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>194</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>305</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month       product_name  order_num\n",
       "0             201901       Road-150 Red        279\n",
       "1             201901     Road-250 Black        245\n",
       "2             201901       Road-250 Red        157\n",
       "3             201901  Road-350-W Yellow        194\n",
       "4             201901  Road-550-W Yellow        305"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求公路自行车不同型号产品销售数量\n",
    "gather_customer_order_road_month = gather_customer_order_road.groupby(by = ['create_year_month','product_name']).agg({'order_num':'sum'}).reset_index()\n",
    "\n",
    "gather_customer_order_road_month.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [],
   "source": [
    "gather_customer_order_road_month['cpzl_zw'] = '公路自行车'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>order_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>1646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201902</td>\n",
       "      <td>1515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201903</td>\n",
       "      <td>1730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201904</td>\n",
       "      <td>1618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201905</td>\n",
       "      <td>1680</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month  order_num\n",
       "0             201901       1646\n",
       "1             201902       1515\n",
       "2             201903       1730\n",
       "3             201904       1618\n",
       "4             201905       1680"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每个月公路自行车累计销售数量\n",
    "gather_customer_order_road_month_sum = gather_customer_order_road_month.groupby(['create_year_month']).agg({'order_num':'sum'}).reset_index()\n",
    "\n",
    "gather_customer_order_road_month_sum.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_num_x</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>order_num_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>279</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>245</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>157</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>194</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>305</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month       product_name  order_num_x cpzl_zw  order_num_y\n",
       "0             201901       Road-150 Red          279   公路自行车         1646\n",
       "1             201901     Road-250 Black          245   公路自行车         1646\n",
       "2             201901       Road-250 Red          157   公路自行车         1646\n",
       "3             201901  Road-350-W Yellow          194   公路自行车         1646\n",
       "4             201901  Road-550-W Yellow          305   公路自行车         1646"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合并公路自行车gather_customer_order_road_month与每月累计销售数量\n",
    "#用于计算不同型号产品的占比\n",
    "gather_customer_order_road_month = pd.merge(gather_customer_order_road_month,gather_customer_order_road_month_sum,on='create_year_month')\n",
    "\n",
    "gather_customer_order_road_month.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**山地自行车**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [],
   "source": [
    "gather_customer_order_Mountain = gather_customer_order[gather_customer_order['cpzl_zw'] == '山地自行车']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "#求山地自行车不同型号产品销售数量\n",
    "gather_customer_order_Mountain_month = gather_customer_order_Mountain.groupby(['create_year_month','product_name']).agg({'order_num':'sum'}).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [],
   "source": [
    "gather_customer_order_Mountain_month['cpzl_zw'] = '山地自行车'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_num_x</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>order_num_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>49</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201901</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>34</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201901</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>322</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201901</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>350</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201901</td>\n",
       "      <td>Mountain-400-W Silver</td>\n",
       "      <td>120</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month           product_name  order_num_x cpzl_zw  order_num_y\n",
       "0             201901     Mountain-100 Black           49   山地自行车          955\n",
       "1             201901    Mountain-100 Silver           34   山地自行车          955\n",
       "2             201901     Mountain-200 Black          322   山地自行车          955\n",
       "3             201901    Mountain-200 Silver          350   山地自行车          955\n",
       "4             201901  Mountain-400-W Silver          120   山地自行车          955"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每个月公路自行车累计销售数量\n",
    "gather_customer_order_Mountain_month_sum = gather_customer_order_Mountain_month.groupby(['create_year_month']).agg({'order_num':'sum'}).reset_index()\n",
    "\n",
    "#合并山地自行车hz_customer_order_Mountain_month与每月累计销售数量\n",
    "#用于计算不同型号产品的占比\n",
    "gather_customer_order_Mountain_month = pd.merge(gather_customer_order_Mountain_month,gather_customer_order_Mountain_month_sum,on='create_year_month')\n",
    "\n",
    "gather_customer_order_Mountain_month.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**旅游自行车**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [],
   "source": [
    "gather_customer_order_tour = gather_customer_order[gather_customer_order['cpzl_zw'] == '旅游自行车']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_num_x</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>order_num_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>113</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201901</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>135</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201901</td>\n",
       "      <td>Touring-2000 Blue</td>\n",
       "      <td>92</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201901</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>49</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201901</td>\n",
       "      <td>Touring-3000 Yellow</td>\n",
       "      <td>46</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>435</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month         product_name  order_num_x cpzl_zw  order_num_y\n",
       "0             201901    Touring-1000 Blue          113   旅游自行车          435\n",
       "1             201901  Touring-1000 Yellow          135   旅游自行车          435\n",
       "2             201901    Touring-2000 Blue           92   旅游自行车          435\n",
       "3             201901    Touring-3000 Blue           49   旅游自行车          435\n",
       "4             201901  Touring-3000 Yellow           46   旅游自行车          435"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求旅游自行车不同型号产品销售数量\n",
    "gather_customer_order_tour_month = gather_customer_order_tour.groupby(['create_year_month','product_name']).agg({'order_num':'sum'}).reset_index()\n",
    "\n",
    "gather_customer_order_tour_month['cpzl_zw'] = '旅游自行车'\n",
    "\n",
    "gather_customer_order_tour_month_sum = gather_customer_order_tour.groupby(['create_year_month']).agg({'order_num':'sum'}).reset_index()\n",
    "gather_customer_order_tour_month =pd.merge(gather_customer_order_tour_month,gather_customer_order_tour_month_sum,on='create_year_month')\n",
    "\n",
    "gather_customer_order_tour_month.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_num_x</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>order_num_y</th>\n",
       "      <th>order_num_proportio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>279</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.169502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>245</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.148846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>157</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.095383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>194</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.117861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>305</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.185298</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-650 Black</td>\n",
       "      <td>77</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.046780</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-650 Red</td>\n",
       "      <td>91</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.055286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-750 Black</td>\n",
       "      <td>298</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.181045</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>305</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.201320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>231</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.152475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>138</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.091089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>176</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.116172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>246</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.162376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-650 Black</td>\n",
       "      <td>78</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.051485</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-650 Red</td>\n",
       "      <td>88</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.058086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>201902</td>\n",
       "      <td>Road-750 Black</td>\n",
       "      <td>253</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1515</td>\n",
       "      <td>0.166997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>316</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.182659</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>213</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.123121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>147</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.084971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>226</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.130636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>305</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.176301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-650 Black</td>\n",
       "      <td>90</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.052023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-650 Red</td>\n",
       "      <td>91</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.052601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>201903</td>\n",
       "      <td>Road-750 Black</td>\n",
       "      <td>342</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1730</td>\n",
       "      <td>0.197688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>201904</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>310</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1618</td>\n",
       "      <td>0.191595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>201904</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>233</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1618</td>\n",
       "      <td>0.144005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>201904</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>134</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1618</td>\n",
       "      <td>0.082818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>201904</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>206</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1618</td>\n",
       "      <td>0.127318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>201904</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>294</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1618</td>\n",
       "      <td>0.181706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>201904</td>\n",
       "      <td>Road-650 Black</td>\n",
       "      <td>67</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1618</td>\n",
       "      <td>0.041409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>201912</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>123</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>438</td>\n",
       "      <td>0.280822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>201912</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>144</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>438</td>\n",
       "      <td>0.328767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>201912</td>\n",
       "      <td>Touring-2000 Blue</td>\n",
       "      <td>72</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>438</td>\n",
       "      <td>0.164384</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>201912</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>59</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>438</td>\n",
       "      <td>0.134703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>201912</td>\n",
       "      <td>Touring-3000 Yellow</td>\n",
       "      <td>40</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>438</td>\n",
       "      <td>0.091324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>202001</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>146</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>474</td>\n",
       "      <td>0.308017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>202001</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>129</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>474</td>\n",
       "      <td>0.272152</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>202001</td>\n",
       "      <td>Touring-2000 Blue</td>\n",
       "      <td>79</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>474</td>\n",
       "      <td>0.166667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>202001</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>53</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>474</td>\n",
       "      <td>0.111814</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>202001</td>\n",
       "      <td>Touring-3000 Yellow</td>\n",
       "      <td>67</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>474</td>\n",
       "      <td>0.141350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>202002</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>158</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>530</td>\n",
       "      <td>0.298113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>202002</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>172</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>530</td>\n",
       "      <td>0.324528</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>202002</td>\n",
       "      <td>Touring-2000 Blue</td>\n",
       "      <td>71</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>530</td>\n",
       "      <td>0.133962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>202002</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>73</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>530</td>\n",
       "      <td>0.137736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>202002</td>\n",
       "      <td>Touring-3000 Yellow</td>\n",
       "      <td>56</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>530</td>\n",
       "      <td>0.105660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>202003</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>302</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>962</td>\n",
       "      <td>0.313929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>202003</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>247</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>962</td>\n",
       "      <td>0.256757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>202003</td>\n",
       "      <td>Touring-2000 Blue</td>\n",
       "      <td>160</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>962</td>\n",
       "      <td>0.166320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>202003</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>111</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>962</td>\n",
       "      <td>0.115385</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>202003</td>\n",
       "      <td>Touring-3000 Yellow</td>\n",
       "      <td>142</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>962</td>\n",
       "      <td>0.147609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>202004</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>67</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>252</td>\n",
       "      <td>0.265873</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>202004</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>70</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>252</td>\n",
       "      <td>0.277778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>202004</td>\n",
       "      <td>Touring-2000 Blue</td>\n",
       "      <td>36</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>252</td>\n",
       "      <td>0.142857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>202004</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>25</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>252</td>\n",
       "      <td>0.099206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>202004</td>\n",
       "      <td>Touring-3000 Yellow</td>\n",
       "      <td>54</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>252</td>\n",
       "      <td>0.214286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>202005</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>86</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>234</td>\n",
       "      <td>0.367521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>202005</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>51</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>234</td>\n",
       "      <td>0.217949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>202005</td>\n",
       "      <td>Touring-2000 Blue</td>\n",
       "      <td>45</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>234</td>\n",
       "      <td>0.192308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>202005</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>25</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>234</td>\n",
       "      <td>0.106838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>202005</td>\n",
       "      <td>Touring-3000 Yellow</td>\n",
       "      <td>27</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>234</td>\n",
       "      <td>0.115385</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>340 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_num_x cpzl_zw  order_num_y  \\\n",
       "0              201901         Road-150 Red          279   公路自行车         1646   \n",
       "1              201901       Road-250 Black          245   公路自行车         1646   \n",
       "2              201901         Road-250 Red          157   公路自行车         1646   \n",
       "3              201901    Road-350-W Yellow          194   公路自行车         1646   \n",
       "4              201901    Road-550-W Yellow          305   公路自行车         1646   \n",
       "5              201901       Road-650 Black           77   公路自行车         1646   \n",
       "6              201901         Road-650 Red           91   公路自行车         1646   \n",
       "7              201901       Road-750 Black          298   公路自行车         1646   \n",
       "8              201902         Road-150 Red          305   公路自行车         1515   \n",
       "9              201902       Road-250 Black          231   公路自行车         1515   \n",
       "10             201902         Road-250 Red          138   公路自行车         1515   \n",
       "11             201902    Road-350-W Yellow          176   公路自行车         1515   \n",
       "12             201902    Road-550-W Yellow          246   公路自行车         1515   \n",
       "13             201902       Road-650 Black           78   公路自行车         1515   \n",
       "14             201902         Road-650 Red           88   公路自行车         1515   \n",
       "15             201902       Road-750 Black          253   公路自行车         1515   \n",
       "16             201903         Road-150 Red          316   公路自行车         1730   \n",
       "17             201903       Road-250 Black          213   公路自行车         1730   \n",
       "18             201903         Road-250 Red          147   公路自行车         1730   \n",
       "19             201903    Road-350-W Yellow          226   公路自行车         1730   \n",
       "20             201903    Road-550-W Yellow          305   公路自行车         1730   \n",
       "21             201903       Road-650 Black           90   公路自行车         1730   \n",
       "22             201903         Road-650 Red           91   公路自行车         1730   \n",
       "23             201903       Road-750 Black          342   公路自行车         1730   \n",
       "24             201904         Road-150 Red          310   公路自行车         1618   \n",
       "25             201904       Road-250 Black          233   公路自行车         1618   \n",
       "26             201904         Road-250 Red          134   公路自行车         1618   \n",
       "27             201904    Road-350-W Yellow          206   公路自行车         1618   \n",
       "28             201904    Road-550-W Yellow          294   公路自行车         1618   \n",
       "29             201904       Road-650 Black           67   公路自行车         1618   \n",
       "..                ...                  ...          ...     ...          ...   \n",
       "55             201912    Touring-1000 Blue          123   旅游自行车          438   \n",
       "56             201912  Touring-1000 Yellow          144   旅游自行车          438   \n",
       "57             201912    Touring-2000 Blue           72   旅游自行车          438   \n",
       "58             201912    Touring-3000 Blue           59   旅游自行车          438   \n",
       "59             201912  Touring-3000 Yellow           40   旅游自行车          438   \n",
       "60             202001    Touring-1000 Blue          146   旅游自行车          474   \n",
       "61             202001  Touring-1000 Yellow          129   旅游自行车          474   \n",
       "62             202001    Touring-2000 Blue           79   旅游自行车          474   \n",
       "63             202001    Touring-3000 Blue           53   旅游自行车          474   \n",
       "64             202001  Touring-3000 Yellow           67   旅游自行车          474   \n",
       "65             202002    Touring-1000 Blue          158   旅游自行车          530   \n",
       "66             202002  Touring-1000 Yellow          172   旅游自行车          530   \n",
       "67             202002    Touring-2000 Blue           71   旅游自行车          530   \n",
       "68             202002    Touring-3000 Blue           73   旅游自行车          530   \n",
       "69             202002  Touring-3000 Yellow           56   旅游自行车          530   \n",
       "70             202003    Touring-1000 Blue          302   旅游自行车          962   \n",
       "71             202003  Touring-1000 Yellow          247   旅游自行车          962   \n",
       "72             202003    Touring-2000 Blue          160   旅游自行车          962   \n",
       "73             202003    Touring-3000 Blue          111   旅游自行车          962   \n",
       "74             202003  Touring-3000 Yellow          142   旅游自行车          962   \n",
       "75             202004    Touring-1000 Blue           67   旅游自行车          252   \n",
       "76             202004  Touring-1000 Yellow           70   旅游自行车          252   \n",
       "77             202004    Touring-2000 Blue           36   旅游自行车          252   \n",
       "78             202004    Touring-3000 Blue           25   旅游自行车          252   \n",
       "79             202004  Touring-3000 Yellow           54   旅游自行车          252   \n",
       "80             202005    Touring-1000 Blue           86   旅游自行车          234   \n",
       "81             202005  Touring-1000 Yellow           51   旅游自行车          234   \n",
       "82             202005    Touring-2000 Blue           45   旅游自行车          234   \n",
       "83             202005    Touring-3000 Blue           25   旅游自行车          234   \n",
       "84             202005  Touring-3000 Yellow           27   旅游自行车          234   \n",
       "\n",
       "    order_num_proportio  \n",
       "0              0.169502  \n",
       "1              0.148846  \n",
       "2              0.095383  \n",
       "3              0.117861  \n",
       "4              0.185298  \n",
       "5              0.046780  \n",
       "6              0.055286  \n",
       "7              0.181045  \n",
       "8              0.201320  \n",
       "9              0.152475  \n",
       "10             0.091089  \n",
       "11             0.116172  \n",
       "12             0.162376  \n",
       "13             0.051485  \n",
       "14             0.058086  \n",
       "15             0.166997  \n",
       "16             0.182659  \n",
       "17             0.123121  \n",
       "18             0.084971  \n",
       "19             0.130636  \n",
       "20             0.176301  \n",
       "21             0.052023  \n",
       "22             0.052601  \n",
       "23             0.197688  \n",
       "24             0.191595  \n",
       "25             0.144005  \n",
       "26             0.082818  \n",
       "27             0.127318  \n",
       "28             0.181706  \n",
       "29             0.041409  \n",
       "..                  ...  \n",
       "55             0.280822  \n",
       "56             0.328767  \n",
       "57             0.164384  \n",
       "58             0.134703  \n",
       "59             0.091324  \n",
       "60             0.308017  \n",
       "61             0.272152  \n",
       "62             0.166667  \n",
       "63             0.111814  \n",
       "64             0.141350  \n",
       "65             0.298113  \n",
       "66             0.324528  \n",
       "67             0.133962  \n",
       "68             0.137736  \n",
       "69             0.105660  \n",
       "70             0.313929  \n",
       "71             0.256757  \n",
       "72             0.166320  \n",
       "73             0.115385  \n",
       "74             0.147609  \n",
       "75             0.265873  \n",
       "76             0.277778  \n",
       "77             0.142857  \n",
       "78             0.099206  \n",
       "79             0.214286  \n",
       "80             0.367521  \n",
       "81             0.217949  \n",
       "82             0.192308  \n",
       "83             0.106838  \n",
       "84             0.115385  \n",
       "\n",
       "[340 rows x 6 columns]"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将山地自行车、旅游自行车、公路自行车每月销量信息合并\n",
    "gather_customer_order_month = pd.concat([gather_customer_order_road_month,gather_customer_order_Mountain_month,gather_customer_order_tour_month])\n",
    "    \n",
    "#各类自行车，销售量占每月自行车总销售量比率\n",
    "gather_customer_order_month['order_num_proportio'] = gather_customer_order_month['order_num_x']/gather_customer_order_month['order_num_y']\n",
    "\n",
    "gather_customer_order_month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>279</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.169502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>245</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.148846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>157</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.095383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>194</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.117861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>305</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.185298</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month       product_name  order_month_product cpzl_zw  \\\n",
       "0             201901       Road-150 Red                  279   公路自行车   \n",
       "1             201901     Road-250 Black                  245   公路自行车   \n",
       "2             201901       Road-250 Red                  157   公路自行车   \n",
       "3             201901  Road-350-W Yellow                  194   公路自行车   \n",
       "4             201901  Road-550-W Yellow                  305   公路自行车   \n",
       "\n",
       "   sum_order_month  order_num_proportio  \n",
       "0             1646             0.169502  \n",
       "1             1646             0.148846  \n",
       "2             1646             0.095383  \n",
       "3             1646             0.117861  \n",
       "4             1646             0.185298  "
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#order_month_product当月产品累计销量\n",
    "#sum_order_month当月自行车总销量\n",
    "gather_customer_order_month.rename(columns={'order_num_x':'order_month_product','order_num_y':'sum_order_month'},inplace=True)\n",
    "\n",
    "gather_customer_order_month.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字段注释：\n",
    "\n",
    "create_year_month：时间，product_name：产品名，order_month_product：本月产品累计销量，sum_order_month：当月自行车总销量，\n",
    "\n",
    "order_num_proportio：本月产品销量占比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #将数据存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/adventure_ods?charset=gbk')\n",
    "# datafrog=engine\n",
    "# gather_customer_order_month.to_sql('pt_bicycle_product_sales_order_month_4',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**计算2019年11月自行车环比**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>42</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.040856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>31</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.030156</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "63             201910   Mountain-100 Black                   42   山地自行车   \n",
       "70             201911   Mountain-100 Black                   50   山地自行车   \n",
       "64             201910  Mountain-100 Silver                   31   山地自行车   \n",
       "\n",
       "    sum_order_month  order_num_proportio  \n",
       "63             1028             0.040856  \n",
       "70             1088             0.045956  \n",
       "64             1028             0.030156  "
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算11月环比，先筛选10月11月数据\n",
    "gather_customer_order_month_10_11 = gather_customer_order_month[gather_customer_order_month.create_year_month.isin(['201910','201911'])]\n",
    "\n",
    "#排序。将10月11月自行车销售信息排序\n",
    "gather_customer_order_month_10_11 = gather_customer_order_month_10_11.sort_values(by = ['product_name','create_year_month'])\n",
    "\n",
    "gather_customer_order_month_10_11.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mountain-100 Black',\n",
       " 'Mountain-100 Silver',\n",
       " 'Mountain-200 Black',\n",
       " 'Mountain-200 Silver',\n",
       " 'Mountain-400-W Silver',\n",
       " 'Mountain-500 Black',\n",
       " 'Mountain-500 Silver',\n",
       " 'Road-150 Red',\n",
       " 'Road-250 Black',\n",
       " 'Road-250 Red',\n",
       " 'Road-350-W Yellow',\n",
       " 'Road-550-W Yellow',\n",
       " 'Road-650 Black',\n",
       " 'Road-650 Red',\n",
       " 'Road-750 Black',\n",
       " 'Touring-1000 Blue',\n",
       " 'Touring-1000 Yellow',\n",
       " 'Touring-2000 Blue',\n",
       " 'Touring-3000 Blue',\n",
       " 'Touring-3000 Yellow']"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "product_name  = list(gather_customer_order_month_10_11.product_name.drop_duplicates())\n",
    "product_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "      <th>order_num_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>42</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.040856</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045956</td>\n",
       "      <td>0.190476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>31</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.030156</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>36</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.033088</td>\n",
       "      <td>0.161290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>379</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.368677</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "63             201910   Mountain-100 Black                   42   山地自行车   \n",
       "70             201911   Mountain-100 Black                   50   山地自行车   \n",
       "64             201910  Mountain-100 Silver                   31   山地自行车   \n",
       "71             201911  Mountain-100 Silver                   36   山地自行车   \n",
       "65             201910   Mountain-200 Black                  379   山地自行车   \n",
       "\n",
       "    sum_order_month  order_num_proportio  order_num_diff  \n",
       "63             1028             0.040856        0.000000  \n",
       "70             1088             0.045956        0.190476  \n",
       "64             1028             0.030156        0.000000  \n",
       "71             1088             0.033088        0.161290  \n",
       "65             1028             0.368677        0.000000  "
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算自行车销售数量环比\n",
    "product_name_list=list(gather_customer_order_month_10_11.product_name.drop_duplicates())\n",
    "\n",
    "order_top_x = pd.Series([])\n",
    "for i in product_name_list:\n",
    "    a=gather_customer_order_month_10_11.loc[gather_customer_order_month_10_11['product_name']==i]['order_month_product'].pct_change().fillna(0)\n",
    "    \n",
    "    order_top_x =order_top_x .append(a)\n",
    "    \n",
    "# 重命名\n",
    "gather_customer_order_month_10_11['order_num_diff'] = order_top_x\n",
    "gather_customer_order_month_10_11.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "      <th>order_num_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045956</td>\n",
       "      <td>0.190476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>36</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.033088</td>\n",
       "      <td>0.161290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>374</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.343750</td>\n",
       "      <td>-0.013193</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "70             201911   Mountain-100 Black                   50   山地自行车   \n",
       "71             201911  Mountain-100 Silver                   36   山地自行车   \n",
       "72             201911   Mountain-200 Black                  374   山地自行车   \n",
       "\n",
       "    sum_order_month  order_num_proportio  order_num_diff  \n",
       "70             1088             0.045956        0.190476  \n",
       "71             1088             0.033088        0.161290  \n",
       "72             1088             0.343750       -0.013193  "
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#筛选出11月自行车数\n",
    "gather_customer_order_month_11 = gather_customer_order_month_10_11[gather_customer_order_month_10_11['create_year_month'] == 201911]\n",
    "gather_customer_order_month_11.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**计算2019年1月至11月产品累计销量**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>279</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.169502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>245</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.148846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>157</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.095383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>194</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.117861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201901</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>305</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>1646</td>\n",
       "      <td>0.185298</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month       product_name  order_month_product cpzl_zw  \\\n",
       "0             201901       Road-150 Red                  279   公路自行车   \n",
       "1             201901     Road-250 Black                  245   公路自行车   \n",
       "2             201901       Road-250 Red                  157   公路自行车   \n",
       "3             201901  Road-350-W Yellow                  194   公路自行车   \n",
       "4             201901  Road-550-W Yellow                  305   公路自行车   \n",
       "\n",
       "   sum_order_month  order_num_proportio  \n",
       "0             1646             0.169502  \n",
       "1             1646             0.148846  \n",
       "2             1646             0.095383  \n",
       "3             1646             0.117861  \n",
       "4             1646             0.185298  "
      ]
     },
     "execution_count": 178,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#筛选2019年1月至11月自行车数据，这里使用的是‘~’取对立面\n",
    "gather_customer_order_month_1_11 =  gather_customer_order_month[~gather_customer_order_month['create_year_month'].isin(['201912','202001'])]\n",
    "\n",
    "gather_customer_order_month_1_11.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>product_name</th>\n",
       "      <th>sum_order_1_11</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>5822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>5525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Mountain-400-W Silver</td>\n",
       "      <td>1739</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            product_name  sum_order_1_11\n",
       "0     Mountain-100 Black             636\n",
       "1    Mountain-100 Silver             595\n",
       "2     Mountain-200 Black            5822\n",
       "3    Mountain-200 Silver            5525\n",
       "4  Mountain-400-W Silver            1739"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算2019年1月至11月自行车累计销量\n",
    "gather_customer_order_month_1_11_sum = gather_customer_order_month_1_11.groupby(by = 'product_name').order_month_product.sum().reset_index()\n",
    "\n",
    "#重命名sum_order_1_11：1-11月产品累计销量\n",
    "gather_customer_order_month_1_11_sum = gather_customer_order_month_1_11_sum.rename(columns = {'order_month_product':'sum_order_1_11'})\n",
    "\n",
    "gather_customer_order_month_1_11_sum.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**2019年11月自行车产品销量、环比、累计销量**\n",
    "\n",
    "累计销量我们在gather_customer_order_month_1_11_sum中已计算好，11月自行车环比、及产品销量占比在gather_customer_order_month_11已计算好，这里我们只需\n",
    "\n",
    "将两张表关联起来，用pd.merge()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "      <th>order_num_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045956</td>\n",
       "      <td>0.190476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>36</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.033088</td>\n",
       "      <td>0.161290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>374</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.343750</td>\n",
       "      <td>-0.013193</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "70             201911   Mountain-100 Black                   50   山地自行车   \n",
       "71             201911  Mountain-100 Silver                   36   山地自行车   \n",
       "72             201911   Mountain-200 Black                  374   山地自行车   \n",
       "\n",
       "    sum_order_month  order_num_proportio  order_num_diff  \n",
       "70             1088             0.045956        0.190476  \n",
       "71             1088             0.033088        0.161290  \n",
       "72             1088             0.343750       -0.013193  "
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#观察表数据\n",
    "gather_customer_order_month_11.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>product_name</th>\n",
       "      <th>sum_order_1_11</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>5822</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          product_name  sum_order_1_11\n",
       "0   Mountain-100 Black             636\n",
       "1  Mountain-100 Silver             595\n",
       "2   Mountain-200 Black            5822"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#观察表数据\n",
    "gather_customer_order_month_1_11_sum.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font face=\"黑体\" color=#DC143C> 作业 3.3.9、以gather_customer_order_month_11为主，合并gather_customer_order_month_1_11_sum表，主键为product_name\n",
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "      <th>order_num_diff</th>\n",
       "      <th>sum_order_1_11</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045956</td>\n",
       "      <td>0.190476</td>\n",
       "      <td>636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>36</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.033088</td>\n",
       "      <td>0.161290</td>\n",
       "      <td>595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>374</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.343750</td>\n",
       "      <td>-0.013193</td>\n",
       "      <td>5822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>395</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.363051</td>\n",
       "      <td>0.106443</td>\n",
       "      <td>5525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-400-W Silver</td>\n",
       "      <td>132</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.121324</td>\n",
       "      <td>0.047619</td>\n",
       "      <td>1739</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   create_year_month           product_name  order_month_product cpzl_zw  \\\n",
       "0             201911     Mountain-100 Black                   50   山地自行车   \n",
       "1             201911    Mountain-100 Silver                   36   山地自行车   \n",
       "2             201911     Mountain-200 Black                  374   山地自行车   \n",
       "3             201911    Mountain-200 Silver                  395   山地自行车   \n",
       "4             201911  Mountain-400-W Silver                  132   山地自行车   \n",
       "\n",
       "   sum_order_month  order_num_proportio  order_num_diff  sum_order_1_11  \n",
       "0             1088             0.045956        0.190476             636  \n",
       "1             1088             0.033088        0.161290             595  \n",
       "2             1088             0.343750       -0.013193            5822  \n",
       "3             1088             0.363051        0.106443            5525  \n",
       "4             1088             0.121324        0.047619            1739  "
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按相同字段product_name产品名，合并两张表\n",
    "gather_customer_order_month_11 = pd.merge(gather_customer_order_month_11,gather_customer_order_month_1_11_sum,on='product_name')\n",
    "\n",
    "gather_customer_order_month_11.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字段注释：\n",
    "\n",
    "create_year_month：时间；product_name：产品，order_month_product：产品本月累计销量，cpzl_zw：产品类别，sum_order_month：当月自行车总销量，\n",
    "\n",
    "order_num_proportio：产品本月占比，order_num_diff：产品本月环比，sum_order_1_11：1-11月产品累计销量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/adventure_ods?charset=gbk')\n",
    "# datafrog=engine\n",
    "# gather_customer_order_month_11.to_sql('pt_bicycle_product_sales_order_month_11',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 四、用户行为分析\n",
    "\n",
    "这里我们需要使用订单明细表：ods_sales_orders，ods_customer用户表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [],
   "source": [
    "#读取数据库客户信息表\n",
    "engine = create_engine('mysql://frogdata001:Frogdata!123@106.13.128.83:3306/adventure_ods?charset=gbk')\n",
    "datafrog=engine\n",
    "df_CUSTOMER = pd.read_sql_query(\"select customer_key,birth_date,gender,marital_status from ods_customer where create_date < '2019-12-1'\",con = datafrog)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [],
   "source": [
    "#读取数据库销售订单表\n",
    "engine = create_engine('mysql://frogdata001:Frogdata!123@106.13.128.83:3306/adventure_ods?charset=gbk')\n",
    "datafrog=engine\n",
    "df_sales_orders_11 = pd.read_sql_query(\"select *  from ods_sales_orders where create_date>='2019-11-1' and   create_date<'2019-12-1'\",con = datafrog)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "销售订单表中仅客户编号，无客户年龄性别等信息，需要将销售订单表和客户信息表合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sales_order_key</th>\n",
       "      <th>create_date</th>\n",
       "      <th>customer_key</th>\n",
       "      <th>product_key</th>\n",
       "      <th>english_product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>unit_price</th>\n",
       "      <th>birth_date</th>\n",
       "      <th>gender</th>\n",
       "      <th>marital_status</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>130506</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>203511</td>\n",
       "      <td>530</td>\n",
       "      <td>Touring Tire Tube</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>4.99</td>\n",
       "      <td>1971-03-11</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>130507</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>525075</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.99</td>\n",
       "      <td>1982-12-17</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>130508</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>756867</td>\n",
       "      <td>537</td>\n",
       "      <td>HL Mountain Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>35.00</td>\n",
       "      <td>1980-02-22</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   sales_order_key create_date customer_key product_key english_product_name  \\\n",
       "0           130506  2019-11-01       203511         530    Touring Tire Tube   \n",
       "1           130507  2019-11-01       525075         222     Sport-100 Helmet   \n",
       "2           130508  2019-11-01       756867         537     HL Mountain Tire   \n",
       "\n",
       "  cpzl_zw cplb_zw  unit_price  birth_date gender marital_status  \n",
       "0   轮胎和内胎      配件        4.99  1971-03-11      M              S  \n",
       "1      头盔      配件       34.99  1982-12-17      M              M  \n",
       "2   轮胎和内胎      配件       35.00  1980-02-22      F              M  "
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#pd.merge\n",
    "sales_customer_order_11=pd.merge(df_sales_orders_11,df_CUSTOMER,on='customer_key',how='left')\n",
    "\n",
    "sales_customer_order_11.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sales_order_key</th>\n",
       "      <th>create_date</th>\n",
       "      <th>customer_key</th>\n",
       "      <th>product_key</th>\n",
       "      <th>english_product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>unit_price</th>\n",
       "      <th>birth_date</th>\n",
       "      <th>gender</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>birth_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>130506</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>203511</td>\n",
       "      <td>530</td>\n",
       "      <td>Touring Tire Tube</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>4.99</td>\n",
       "      <td>1971-03-11</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>130507</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>525075</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.99</td>\n",
       "      <td>1982-12-17</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>130508</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>756867</td>\n",
       "      <td>537</td>\n",
       "      <td>HL Mountain Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>35.00</td>\n",
       "      <td>1980-02-22</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1980</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   sales_order_key create_date customer_key product_key english_product_name  \\\n",
       "0           130506  2019-11-01       203511         530    Touring Tire Tube   \n",
       "1           130507  2019-11-01       525075         222     Sport-100 Helmet   \n",
       "2           130508  2019-11-01       756867         537     HL Mountain Tire   \n",
       "\n",
       "  cpzl_zw cplb_zw  unit_price  birth_date gender marital_status birth_year  \n",
       "0   轮胎和内胎      配件        4.99  1971-03-11      M              S       1971  \n",
       "1      头盔      配件       34.99  1982-12-17      M              M       1982  \n",
       "2   轮胎和内胎      配件       35.00  1980-02-22      F              M       1980  "
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_birth_year = sales_customer_order_11['birth_date'].str.split('-',expand = True).rename(columns = {0:'birth_year'}).\\\n",
    "                                                drop(labels = [1,2],axis = 1)\n",
    "sales_customer_order_11 = pd.concat([sales_customer_order_11,customer_birth_year],axis = 1)\n",
    "sales_customer_order_11.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.1、用户年龄分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {},
   "outputs": [],
   "source": [
    "#修改出生年为int数据类型\n",
    "sales_customer_order_11['birth_year']=sales_customer_order_11['birth_year'].fillna(0)\n",
    "sales_customer_order_11['birth_year'] = sales_customer_order_11['birth_year'].astype('int')\n",
    "\n",
    "# 计算用户年龄\n",
    "sales_customer_order_11['customer_age'] = 2019 - sales_customer_order_11['birth_year']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sales_order_key</th>\n",
       "      <th>create_date</th>\n",
       "      <th>customer_key</th>\n",
       "      <th>product_key</th>\n",
       "      <th>english_product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>unit_price</th>\n",
       "      <th>birth_date</th>\n",
       "      <th>gender</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>birth_year</th>\n",
       "      <th>customer_age</th>\n",
       "      <th>age_level</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>130506</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>203511</td>\n",
       "      <td>530</td>\n",
       "      <td>Touring Tire Tube</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>4.9900</td>\n",
       "      <td>1971-03-11</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1971</td>\n",
       "      <td>48</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>130507</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>525075</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.9900</td>\n",
       "      <td>1982-12-17</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>130508</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>756867</td>\n",
       "      <td>537</td>\n",
       "      <td>HL Mountain Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>35.0000</td>\n",
       "      <td>1980-02-22</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1980</td>\n",
       "      <td>39</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>130509</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>742098</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.9900</td>\n",
       "      <td>1981-09-06</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1981</td>\n",
       "      <td>38</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>130510</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>314788</td>\n",
       "      <td>581</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1700.9900</td>\n",
       "      <td>1962-06-21</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>130511</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>515066</td>\n",
       "      <td>370</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2443.3500</td>\n",
       "      <td>1982-10-17</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>130512</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>301184</td>\n",
       "      <td>479</td>\n",
       "      <td>Road Bottle Cage</td>\n",
       "      <td>瓶子和笼子</td>\n",
       "      <td>配件</td>\n",
       "      <td>8.9900</td>\n",
       "      <td>1974-12-30</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1974</td>\n",
       "      <td>45</td>\n",
       "      <td>40-44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>130513</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>611203</td>\n",
       "      <td>357</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2319.9900</td>\n",
       "      <td>1962-08-07</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>130514</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>732668</td>\n",
       "      <td>354</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2071.4196</td>\n",
       "      <td>1964-10-21</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1964</td>\n",
       "      <td>55</td>\n",
       "      <td>50-54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>130515</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>313465</td>\n",
       "      <td>363</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1962-05-05</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>130516</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>951892</td>\n",
       "      <td>529</td>\n",
       "      <td>Road Tire Tube</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>3.9900</td>\n",
       "      <td>1972-05-19</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1972</td>\n",
       "      <td>47</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>130517</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>458300</td>\n",
       "      <td>361</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1982-12-04</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>130518</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>239001</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.9900</td>\n",
       "      <td>1967-01-23</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1967</td>\n",
       "      <td>52</td>\n",
       "      <td>50-54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>130519</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>134463</td>\n",
       "      <td>463</td>\n",
       "      <td>Half-Finger Gloves</td>\n",
       "      <td>手套</td>\n",
       "      <td>服装</td>\n",
       "      <td>24.4900</td>\n",
       "      <td>1970-04-14</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1970</td>\n",
       "      <td>49</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>130520</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>231534</td>\n",
       "      <td>480</td>\n",
       "      <td>Patch Kit/8 Patches</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>2.2900</td>\n",
       "      <td>1980-11-17</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1980</td>\n",
       "      <td>39</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>130521</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>193091</td>\n",
       "      <td>605</td>\n",
       "      <td>Road-750 Black</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>539.9900</td>\n",
       "      <td>1972-07-09</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1972</td>\n",
       "      <td>47</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>130522</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>558859</td>\n",
       "      <td>540</td>\n",
       "      <td>HL Road Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>32.6000</td>\n",
       "      <td>1984-03-18</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1984</td>\n",
       "      <td>35</td>\n",
       "      <td>30-34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>130523</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>882567</td>\n",
       "      <td>234</td>\n",
       "      <td>Long-Sleeve Logo Jersey</td>\n",
       "      <td>运动衫</td>\n",
       "      <td>服装</td>\n",
       "      <td>49.9900</td>\n",
       "      <td>1981-09-14</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1981</td>\n",
       "      <td>38</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>130524</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>126856</td>\n",
       "      <td>361</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1984-05-04</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1984</td>\n",
       "      <td>35</td>\n",
       "      <td>30-34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>130525</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>34218</td>\n",
       "      <td>477</td>\n",
       "      <td>Water Bottle - 30 oz.</td>\n",
       "      <td>瓶子和笼子</td>\n",
       "      <td>配件</td>\n",
       "      <td>4.9900</td>\n",
       "      <td>1969-12-15</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1969</td>\n",
       "      <td>50</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>130526</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>167398</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.9900</td>\n",
       "      <td>1959-09-08</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1959</td>\n",
       "      <td>60</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>130527</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>970211</td>\n",
       "      <td>474</td>\n",
       "      <td>Women's Mountain Shorts</td>\n",
       "      <td>短裤</td>\n",
       "      <td>服装</td>\n",
       "      <td>69.9900</td>\n",
       "      <td>1976-09-18</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1976</td>\n",
       "      <td>43</td>\n",
       "      <td>40-44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>130528</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>282494</td>\n",
       "      <td>363</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1962-12-04</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>130529</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>870635</td>\n",
       "      <td>363</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1980-01-10</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1980</td>\n",
       "      <td>39</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>130530</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>770886</td>\n",
       "      <td>585</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>742.3500</td>\n",
       "      <td>1969-05-12</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1969</td>\n",
       "      <td>50</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>130531</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>275089</td>\n",
       "      <td>567</td>\n",
       "      <td>Touring-3000 Blue</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>742.3500</td>\n",
       "      <td>1971-04-21</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1971</td>\n",
       "      <td>48</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>130532</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>587504</td>\n",
       "      <td>530</td>\n",
       "      <td>Touring Tire Tube</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>4.9900</td>\n",
       "      <td>1980-01-04</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1980</td>\n",
       "      <td>39</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>130533</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>646117</td>\n",
       "      <td>536</td>\n",
       "      <td>ML Mountain Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>29.9900</td>\n",
       "      <td>1973-06-12</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1973</td>\n",
       "      <td>46</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>130534</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>610437</td>\n",
       "      <td>535</td>\n",
       "      <td>LL Mountain Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>24.9900</td>\n",
       "      <td>1983-01-22</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1983</td>\n",
       "      <td>36</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>130535</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>842017</td>\n",
       "      <td>480</td>\n",
       "      <td>Patch Kit/8 Patches</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>2.2900</td>\n",
       "      <td>1981-09-22</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1981</td>\n",
       "      <td>38</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13256</th>\n",
       "      <td>155346</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>451339</td>\n",
       "      <td>530</td>\n",
       "      <td>Touring Tire Tube</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>4.9900</td>\n",
       "      <td>1962-06-03</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13257</th>\n",
       "      <td>155347</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>466395</td>\n",
       "      <td>539</td>\n",
       "      <td>ML Road Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>24.9900</td>\n",
       "      <td>1984-06-21</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1984</td>\n",
       "      <td>35</td>\n",
       "      <td>30-34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13258</th>\n",
       "      <td>155348</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>654984</td>\n",
       "      <td>537</td>\n",
       "      <td>HL Mountain Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>35.0000</td>\n",
       "      <td>1979-06-07</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1979</td>\n",
       "      <td>40</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13259</th>\n",
       "      <td>155349</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>417963</td>\n",
       "      <td>604</td>\n",
       "      <td>Road-750 Black</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>539.9900</td>\n",
       "      <td>1982-05-14</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13260</th>\n",
       "      <td>155350</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>1058297</td>\n",
       "      <td>529</td>\n",
       "      <td>Road Tire Tube</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>3.9900</td>\n",
       "      <td>1979-05-03</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1979</td>\n",
       "      <td>40</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13261</th>\n",
       "      <td>155351</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>720021</td>\n",
       "      <td>475</td>\n",
       "      <td>Women's Mountain Shorts</td>\n",
       "      <td>短裤</td>\n",
       "      <td>服装</td>\n",
       "      <td>69.9900</td>\n",
       "      <td>1985-03-05</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1985</td>\n",
       "      <td>34</td>\n",
       "      <td>30-34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13262</th>\n",
       "      <td>155352</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>288001</td>\n",
       "      <td>485</td>\n",
       "      <td>Fender Set - Mountain</td>\n",
       "      <td>挡泥板</td>\n",
       "      <td>配件</td>\n",
       "      <td>21.9800</td>\n",
       "      <td>1976-05-13</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1976</td>\n",
       "      <td>43</td>\n",
       "      <td>40-44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13263</th>\n",
       "      <td>155353</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>1021447</td>\n",
       "      <td>228</td>\n",
       "      <td>Long-Sleeve Logo Jersey</td>\n",
       "      <td>运动衫</td>\n",
       "      <td>服装</td>\n",
       "      <td>49.9900</td>\n",
       "      <td>1976-07-01</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1976</td>\n",
       "      <td>43</td>\n",
       "      <td>40-44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13264</th>\n",
       "      <td>155354</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>85335</td>\n",
       "      <td>478</td>\n",
       "      <td>Mountain Bottle Cage</td>\n",
       "      <td>瓶子和笼子</td>\n",
       "      <td>配件</td>\n",
       "      <td>9.9900</td>\n",
       "      <td>1981-12-06</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1981</td>\n",
       "      <td>38</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13265</th>\n",
       "      <td>155355</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>173466</td>\n",
       "      <td>373</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2181.5625</td>\n",
       "      <td>1980-08-24</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1980</td>\n",
       "      <td>39</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13266</th>\n",
       "      <td>155356</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>493945</td>\n",
       "      <td>480</td>\n",
       "      <td>Patch Kit/8 Patches</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>2.2900</td>\n",
       "      <td>1980-08-12</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1980</td>\n",
       "      <td>39</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13267</th>\n",
       "      <td>155357</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>852527</td>\n",
       "      <td>225</td>\n",
       "      <td>AWC Logo Cap</td>\n",
       "      <td>帽子</td>\n",
       "      <td>服装</td>\n",
       "      <td>8.9900</td>\n",
       "      <td>1981-01-16</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1981</td>\n",
       "      <td>38</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13268</th>\n",
       "      <td>155358</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>494666</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.9900</td>\n",
       "      <td>1981-11-04</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1981</td>\n",
       "      <td>38</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13269</th>\n",
       "      <td>155359</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>570209</td>\n",
       "      <td>314</td>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>3578.2700</td>\n",
       "      <td>1980-03-05</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1980</td>\n",
       "      <td>39</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13270</th>\n",
       "      <td>155360</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>537280</td>\n",
       "      <td>386</td>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1120.4900</td>\n",
       "      <td>1957-07-17</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1957</td>\n",
       "      <td>62</td>\n",
       "      <td>60-64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13271</th>\n",
       "      <td>155361</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>235798</td>\n",
       "      <td>328</td>\n",
       "      <td>Road-650 Red</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>699.0982</td>\n",
       "      <td>1982-08-26</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13272</th>\n",
       "      <td>155362</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>1022787</td>\n",
       "      <td>359</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1963-09-20</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1963</td>\n",
       "      <td>56</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13273</th>\n",
       "      <td>155363</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>656108</td>\n",
       "      <td>485</td>\n",
       "      <td>Fender Set - Mountain</td>\n",
       "      <td>挡泥板</td>\n",
       "      <td>配件</td>\n",
       "      <td>21.9800</td>\n",
       "      <td>1985-11-12</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1985</td>\n",
       "      <td>34</td>\n",
       "      <td>30-34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13274</th>\n",
       "      <td>155364</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>116530</td>\n",
       "      <td>478</td>\n",
       "      <td>Mountain Bottle Cage</td>\n",
       "      <td>瓶子和笼子</td>\n",
       "      <td>配件</td>\n",
       "      <td>9.9900</td>\n",
       "      <td>1982-04-09</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13275</th>\n",
       "      <td>155365</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>960741</td>\n",
       "      <td>477</td>\n",
       "      <td>Water Bottle - 30 oz.</td>\n",
       "      <td>瓶子和笼子</td>\n",
       "      <td>配件</td>\n",
       "      <td>4.9900</td>\n",
       "      <td>1983-06-01</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1983</td>\n",
       "      <td>36</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13276</th>\n",
       "      <td>155366</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>495837</td>\n",
       "      <td>214</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.9900</td>\n",
       "      <td>1963-01-12</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1963</td>\n",
       "      <td>56</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13277</th>\n",
       "      <td>155367</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>420296</td>\n",
       "      <td>490</td>\n",
       "      <td>Short-Sleeve Classic Jersey</td>\n",
       "      <td>运动衫</td>\n",
       "      <td>服装</td>\n",
       "      <td>53.9900</td>\n",
       "      <td>1957-11-15</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1957</td>\n",
       "      <td>62</td>\n",
       "      <td>60-64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13278</th>\n",
       "      <td>155368</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>241143</td>\n",
       "      <td>231</td>\n",
       "      <td>Long-Sleeve Logo Jersey</td>\n",
       "      <td>运动衫</td>\n",
       "      <td>服装</td>\n",
       "      <td>49.9900</td>\n",
       "      <td>1984-06-16</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1984</td>\n",
       "      <td>35</td>\n",
       "      <td>30-34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13279</th>\n",
       "      <td>155369</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>342549</td>\n",
       "      <td>562</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2384.0700</td>\n",
       "      <td>1983-12-24</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1983</td>\n",
       "      <td>36</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13280</th>\n",
       "      <td>155370</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>749421</td>\n",
       "      <td>222</td>\n",
       "      <td>Sport-100 Helmet</td>\n",
       "      <td>头盔</td>\n",
       "      <td>配件</td>\n",
       "      <td>34.9900</td>\n",
       "      <td>1967-02-18</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1967</td>\n",
       "      <td>52</td>\n",
       "      <td>50-54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13281</th>\n",
       "      <td>155371</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>602045</td>\n",
       "      <td>573</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2384.0700</td>\n",
       "      <td>1982-08-23</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13282</th>\n",
       "      <td>155372</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>776982</td>\n",
       "      <td>371</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2181.5625</td>\n",
       "      <td>1983-10-16</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1983</td>\n",
       "      <td>36</td>\n",
       "      <td>35-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13283</th>\n",
       "      <td>155373</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>1012813</td>\n",
       "      <td>376</td>\n",
       "      <td>Road-250 Black</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2443.3500</td>\n",
       "      <td>1973-08-24</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1973</td>\n",
       "      <td>46</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13284</th>\n",
       "      <td>155374</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>525834</td>\n",
       "      <td>536</td>\n",
       "      <td>ML Mountain Tire</td>\n",
       "      <td>轮胎和内胎</td>\n",
       "      <td>配件</td>\n",
       "      <td>29.9900</td>\n",
       "      <td>1960-02-05</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1960</td>\n",
       "      <td>59</td>\n",
       "      <td>55-59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13285</th>\n",
       "      <td>155375</td>\n",
       "      <td>2019-11-30</td>\n",
       "      <td>269791</td>\n",
       "      <td>482</td>\n",
       "      <td>Racing Socks</td>\n",
       "      <td>袜子</td>\n",
       "      <td>服装</td>\n",
       "      <td>8.9900</td>\n",
       "      <td>1972-02-12</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1972</td>\n",
       "      <td>47</td>\n",
       "      <td>45-49</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>13286 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       sales_order_key create_date customer_key product_key  \\\n",
       "0               130506  2019-11-01       203511         530   \n",
       "1               130507  2019-11-01       525075         222   \n",
       "2               130508  2019-11-01       756867         537   \n",
       "3               130509  2019-11-01       742098         222   \n",
       "4               130510  2019-11-01       314788         581   \n",
       "5               130511  2019-11-01       515066         370   \n",
       "6               130512  2019-11-01       301184         479   \n",
       "7               130513  2019-11-01       611203         357   \n",
       "8               130514  2019-11-01       732668         354   \n",
       "9               130515  2019-11-01       313465         363   \n",
       "10              130516  2019-11-01       951892         529   \n",
       "11              130517  2019-11-01       458300         361   \n",
       "12              130518  2019-11-01       239001         222   \n",
       "13              130519  2019-11-01       134463         463   \n",
       "14              130520  2019-11-01       231534         480   \n",
       "15              130521  2019-11-01       193091         605   \n",
       "16              130522  2019-11-01       558859         540   \n",
       "17              130523  2019-11-01       882567         234   \n",
       "18              130524  2019-11-01       126856         361   \n",
       "19              130525  2019-11-01        34218         477   \n",
       "20              130526  2019-11-01       167398         222   \n",
       "21              130527  2019-11-01       970211         474   \n",
       "22              130528  2019-11-01       282494         363   \n",
       "23              130529  2019-11-01       870635         363   \n",
       "24              130530  2019-11-01       770886         585   \n",
       "25              130531  2019-11-01       275089         567   \n",
       "26              130532  2019-11-01       587504         530   \n",
       "27              130533  2019-11-01       646117         536   \n",
       "28              130534  2019-11-01       610437         535   \n",
       "29              130535  2019-11-01       842017         480   \n",
       "...                ...         ...          ...         ...   \n",
       "13256           155346  2019-11-30       451339         530   \n",
       "13257           155347  2019-11-30       466395         539   \n",
       "13258           155348  2019-11-30       654984         537   \n",
       "13259           155349  2019-11-30       417963         604   \n",
       "13260           155350  2019-11-30      1058297         529   \n",
       "13261           155351  2019-11-30       720021         475   \n",
       "13262           155352  2019-11-30       288001         485   \n",
       "13263           155353  2019-11-30      1021447         228   \n",
       "13264           155354  2019-11-30        85335         478   \n",
       "13265           155355  2019-11-30       173466         373   \n",
       "13266           155356  2019-11-30       493945         480   \n",
       "13267           155357  2019-11-30       852527         225   \n",
       "13268           155358  2019-11-30       494666         222   \n",
       "13269           155359  2019-11-30       570209         314   \n",
       "13270           155360  2019-11-30       537280         386   \n",
       "13271           155361  2019-11-30       235798         328   \n",
       "13272           155362  2019-11-30      1022787         359   \n",
       "13273           155363  2019-11-30       656108         485   \n",
       "13274           155364  2019-11-30       116530         478   \n",
       "13275           155365  2019-11-30       960741         477   \n",
       "13276           155366  2019-11-30       495837         214   \n",
       "13277           155367  2019-11-30       420296         490   \n",
       "13278           155368  2019-11-30       241143         231   \n",
       "13279           155369  2019-11-30       342549         562   \n",
       "13280           155370  2019-11-30       749421         222   \n",
       "13281           155371  2019-11-30       602045         573   \n",
       "13282           155372  2019-11-30       776982         371   \n",
       "13283           155373  2019-11-30      1012813         376   \n",
       "13284           155374  2019-11-30       525834         536   \n",
       "13285           155375  2019-11-30       269791         482   \n",
       "\n",
       "              english_product_name cpzl_zw cplb_zw  unit_price  birth_date  \\\n",
       "0                Touring Tire Tube   轮胎和内胎      配件      4.9900  1971-03-11   \n",
       "1                 Sport-100 Helmet      头盔      配件     34.9900  1982-12-17   \n",
       "2                 HL Mountain Tire   轮胎和内胎      配件     35.0000  1980-02-22   \n",
       "3                 Sport-100 Helmet      头盔      配件     34.9900  1981-09-06   \n",
       "4                Road-350-W Yellow   公路自行车     自行车   1700.9900  1962-06-21   \n",
       "5                     Road-250 Red   公路自行车     自行车   2443.3500  1982-10-17   \n",
       "6                 Road Bottle Cage   瓶子和笼子      配件      8.9900  1974-12-30   \n",
       "7              Mountain-200 Silver   山地自行车     自行车   2319.9900  1962-08-07   \n",
       "8              Mountain-200 Silver   山地自行车     自行车   2071.4196  1964-10-21   \n",
       "9               Mountain-200 Black   山地自行车     自行车   2294.9900  1962-05-05   \n",
       "10                  Road Tire Tube   轮胎和内胎      配件      3.9900  1972-05-19   \n",
       "11              Mountain-200 Black   山地自行车     自行车   2294.9900  1982-12-04   \n",
       "12                Sport-100 Helmet      头盔      配件     34.9900  1967-01-23   \n",
       "13              Half-Finger Gloves      手套      服装     24.4900  1970-04-14   \n",
       "14             Patch Kit/8 Patches   轮胎和内胎      配件      2.2900  1980-11-17   \n",
       "15                  Road-750 Black   公路自行车     自行车    539.9900  1972-07-09   \n",
       "16                    HL Road Tire   轮胎和内胎      配件     32.6000  1984-03-18   \n",
       "17         Long-Sleeve Logo Jersey     运动衫      服装     49.9900  1981-09-14   \n",
       "18              Mountain-200 Black   山地自行车     自行车   2294.9900  1984-05-04   \n",
       "19           Water Bottle - 30 oz.   瓶子和笼子      配件      4.9900  1969-12-15   \n",
       "20                Sport-100 Helmet      头盔      配件     34.9900  1959-09-08   \n",
       "21         Women's Mountain Shorts      短裤      服装     69.9900  1976-09-18   \n",
       "22              Mountain-200 Black   山地自行车     自行车   2294.9900  1962-12-04   \n",
       "23              Mountain-200 Black   山地自行车     自行车   2294.9900  1980-01-10   \n",
       "24               Touring-3000 Blue   旅游自行车     自行车    742.3500  1969-05-12   \n",
       "25               Touring-3000 Blue   旅游自行车     自行车    742.3500  1971-04-21   \n",
       "26               Touring Tire Tube   轮胎和内胎      配件      4.9900  1980-01-04   \n",
       "27                ML Mountain Tire   轮胎和内胎      配件     29.9900  1973-06-12   \n",
       "28                LL Mountain Tire   轮胎和内胎      配件     24.9900  1983-01-22   \n",
       "29             Patch Kit/8 Patches   轮胎和内胎      配件      2.2900  1981-09-22   \n",
       "...                            ...     ...     ...         ...         ...   \n",
       "13256            Touring Tire Tube   轮胎和内胎      配件      4.9900  1962-06-03   \n",
       "13257                 ML Road Tire   轮胎和内胎      配件     24.9900  1984-06-21   \n",
       "13258             HL Mountain Tire   轮胎和内胎      配件     35.0000  1979-06-07   \n",
       "13259               Road-750 Black   公路自行车     自行车    539.9900  1982-05-14   \n",
       "13260               Road Tire Tube   轮胎和内胎      配件      3.9900  1979-05-03   \n",
       "13261      Women's Mountain Shorts      短裤      服装     69.9900  1985-03-05   \n",
       "13262        Fender Set - Mountain     挡泥板      配件     21.9800  1976-05-13   \n",
       "13263      Long-Sleeve Logo Jersey     运动衫      服装     49.9900  1976-07-01   \n",
       "13264         Mountain Bottle Cage   瓶子和笼子      配件      9.9900  1981-12-06   \n",
       "13265               Road-250 Black   公路自行车     自行车   2181.5625  1980-08-24   \n",
       "13266          Patch Kit/8 Patches   轮胎和内胎      配件      2.2900  1980-08-12   \n",
       "13267                 AWC Logo Cap      帽子      服装      8.9900  1981-01-16   \n",
       "13268             Sport-100 Helmet      头盔      配件     34.9900  1981-11-04   \n",
       "13269                 Road-150 Red   公路自行车     自行车   3578.2700  1980-03-05   \n",
       "13270            Road-550-W Yellow   公路自行车     自行车   1120.4900  1957-07-17   \n",
       "13271                 Road-650 Red   公路自行车     自行车    699.0982  1982-08-26   \n",
       "13272           Mountain-200 Black   山地自行车     自行车   2294.9900  1963-09-20   \n",
       "13273        Fender Set - Mountain     挡泥板      配件     21.9800  1985-11-12   \n",
       "13274         Mountain Bottle Cage   瓶子和笼子      配件      9.9900  1982-04-09   \n",
       "13275        Water Bottle - 30 oz.   瓶子和笼子      配件      4.9900  1983-06-01   \n",
       "13276             Sport-100 Helmet      头盔      配件     34.9900  1963-01-12   \n",
       "13277  Short-Sleeve Classic Jersey     运动衫      服装     53.9900  1957-11-15   \n",
       "13278      Long-Sleeve Logo Jersey     运动衫      服装     49.9900  1984-06-16   \n",
       "13279          Touring-1000 Yellow   旅游自行车     自行车   2384.0700  1983-12-24   \n",
       "13280             Sport-100 Helmet      头盔      配件     34.9900  1967-02-18   \n",
       "13281            Touring-1000 Blue   旅游自行车     自行车   2384.0700  1982-08-23   \n",
       "13282                 Road-250 Red   公路自行车     自行车   2181.5625  1983-10-16   \n",
       "13283               Road-250 Black   公路自行车     自行车   2443.3500  1973-08-24   \n",
       "13284             ML Mountain Tire   轮胎和内胎      配件     29.9900  1960-02-05   \n",
       "13285                 Racing Socks      袜子      服装      8.9900  1972-02-12   \n",
       "\n",
       "      gender marital_status  birth_year  customer_age age_level  \n",
       "0          M              S        1971            48     45-49  \n",
       "1          M              M        1982            37     35-39  \n",
       "2          F              M        1980            39     35-39  \n",
       "3          M              M        1981            38     35-39  \n",
       "4          F              M        1962            57     55-59  \n",
       "5          M              S        1982            37     35-39  \n",
       "6          F              S        1974            45     40-44  \n",
       "7          M              M        1962            57     55-59  \n",
       "8          F              S        1964            55     50-54  \n",
       "9          F              S        1962            57     55-59  \n",
       "10         M              M        1972            47     45-49  \n",
       "11         F              M        1982            37     35-39  \n",
       "12         F              M        1967            52     50-54  \n",
       "13         F              S        1970            49     45-49  \n",
       "14         M              M        1980            39     35-39  \n",
       "15         M              M        1972            47     45-49  \n",
       "16         F              M        1984            35     30-34  \n",
       "17         M              S        1981            38     35-39  \n",
       "18         F              M        1984            35     30-34  \n",
       "19         M              M        1969            50     45-49  \n",
       "20         F              M        1959            60     55-59  \n",
       "21         M              S        1976            43     40-44  \n",
       "22         M              M        1962            57     55-59  \n",
       "23         F              S        1980            39     35-39  \n",
       "24         F              M        1969            50     45-49  \n",
       "25         M              M        1971            48     45-49  \n",
       "26         M              S        1980            39     35-39  \n",
       "27         M              S        1973            46     45-49  \n",
       "28         F              S        1983            36     35-39  \n",
       "29         M              M        1981            38     35-39  \n",
       "...      ...            ...         ...           ...       ...  \n",
       "13256      F              S        1962            57     55-59  \n",
       "13257      F              S        1984            35     30-34  \n",
       "13258      M              M        1979            40     35-39  \n",
       "13259      M              S        1982            37     35-39  \n",
       "13260      M              S        1979            40     35-39  \n",
       "13261      M              M        1985            34     30-34  \n",
       "13262      M              M        1976            43     40-44  \n",
       "13263      F              M        1976            43     40-44  \n",
       "13264      M              S        1981            38     35-39  \n",
       "13265      F              S        1980            39     35-39  \n",
       "13266      M              M        1980            39     35-39  \n",
       "13267      M              S        1981            38     35-39  \n",
       "13268      M              M        1981            38     35-39  \n",
       "13269      F              M        1980            39     35-39  \n",
       "13270      F              S        1957            62     60-64  \n",
       "13271      M              S        1982            37     35-39  \n",
       "13272      F              M        1963            56     55-59  \n",
       "13273      M              M        1985            34     30-34  \n",
       "13274      M              S        1982            37     35-39  \n",
       "13275      F              S        1983            36     35-39  \n",
       "13276      F              M        1963            56     55-59  \n",
       "13277      M              S        1957            62     60-64  \n",
       "13278      M              S        1984            35     30-34  \n",
       "13279      F              M        1983            36     35-39  \n",
       "13280      F              S        1967            52     50-54  \n",
       "13281      F              M        1982            37     35-39  \n",
       "13282      M              M        1983            36     35-39  \n",
       "13283      M              M        1973            46     45-49  \n",
       "13284      F              M        1960            59     55-59  \n",
       "13285      M              M        1972            47     45-49  \n",
       "\n",
       "[13286 rows x 14 columns]"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#使用pd.cut,请利用customer_age字段，进行年龄分层,并新增'age_level'分层区间列\n",
    "sales_customer_order_11['age_level'] =pd.cut(sales_customer_order_11['customer_age'],[30,35,40,45,50,55,60,65],labels=[\"30-34\",\"35-39\",\"40-44\",\"45-49\",\"50-54\",\"55-59\",\"60-64\"])\n",
    "sales_customer_order_11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [],
   "source": [
    "#筛选销售订单为自行车的订单信息\n",
    "df_customer_order_bycle = sales_customer_order_11.loc[sales_customer_order_11['cplb_zw'] == '自行车']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aa/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sales_order_key</th>\n",
       "      <th>create_date</th>\n",
       "      <th>customer_key</th>\n",
       "      <th>product_key</th>\n",
       "      <th>english_product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>unit_price</th>\n",
       "      <th>birth_date</th>\n",
       "      <th>gender</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>birth_year</th>\n",
       "      <th>customer_age</th>\n",
       "      <th>age_level</th>\n",
       "      <th>age_level_rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>130510</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>314788</td>\n",
       "      <td>581</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1700.9900</td>\n",
       "      <td>1962-06-21</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "      <td>0.000291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>130511</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>515066</td>\n",
       "      <td>370</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2443.3500</td>\n",
       "      <td>1982-10-17</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "      <td>0.000291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>130513</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>611203</td>\n",
       "      <td>357</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2319.9900</td>\n",
       "      <td>1962-08-07</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "      <td>0.000291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>130514</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>732668</td>\n",
       "      <td>354</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2071.4196</td>\n",
       "      <td>1964-10-21</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1964</td>\n",
       "      <td>55</td>\n",
       "      <td>50-54</td>\n",
       "      <td>0.000291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>130515</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>313465</td>\n",
       "      <td>363</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1962-05-05</td>\n",
       "      <td>F</td>\n",
       "      <td>S</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "      <td>0.000291</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   sales_order_key create_date customer_key product_key english_product_name  \\\n",
       "4           130510  2019-11-01       314788         581    Road-350-W Yellow   \n",
       "5           130511  2019-11-01       515066         370         Road-250 Red   \n",
       "7           130513  2019-11-01       611203         357  Mountain-200 Silver   \n",
       "8           130514  2019-11-01       732668         354  Mountain-200 Silver   \n",
       "9           130515  2019-11-01       313465         363   Mountain-200 Black   \n",
       "\n",
       "  cpzl_zw cplb_zw  unit_price  birth_date gender marital_status  birth_year  \\\n",
       "4   公路自行车     自行车   1700.9900  1962-06-21      F              M        1962   \n",
       "5   公路自行车     自行车   2443.3500  1982-10-17      M              S        1982   \n",
       "7   山地自行车     自行车   2319.9900  1962-08-07      M              M        1962   \n",
       "8   山地自行车     自行车   2071.4196  1964-10-21      F              S        1964   \n",
       "9   山地自行车     自行车   2294.9900  1962-05-05      F              S        1962   \n",
       "\n",
       "   customer_age age_level  age_level_rate  \n",
       "4            57     55-59        0.000291  \n",
       "5            37     35-39        0.000291  \n",
       "7            57     55-59        0.000291  \n",
       "8            55     50-54        0.000291  \n",
       "9            57     55-59        0.000291  "
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算年龄比率\n",
    "df_customer_order_bycle['age_level_rate'] = 1 / len(df_customer_order_bycle)\n",
    "\n",
    "df_customer_order_bycle.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font face=\"黑体\" color=#DC143C> 作业 4.1.5 将年龄分为3个层次，分别为'<=29'、'30-39'、'>=40'\n",
    "    ![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/aa/anaconda3/lib/python3.6/site-packages/pandas/core/indexing.py:537: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  self.obj[item] = s\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sales_order_key</th>\n",
       "      <th>create_date</th>\n",
       "      <th>customer_key</th>\n",
       "      <th>product_key</th>\n",
       "      <th>english_product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>unit_price</th>\n",
       "      <th>birth_date</th>\n",
       "      <th>gender</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>birth_year</th>\n",
       "      <th>customer_age</th>\n",
       "      <th>age_level</th>\n",
       "      <th>age_level_rate</th>\n",
       "      <th>age_level2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>130510</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>314788</td>\n",
       "      <td>581</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1700.99</td>\n",
       "      <td>1962-06-21</td>\n",
       "      <td>F</td>\n",
       "      <td>M</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>&gt;=40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>130511</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>515066</td>\n",
       "      <td>370</td>\n",
       "      <td>Road-250 Red</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2443.35</td>\n",
       "      <td>1982-10-17</td>\n",
       "      <td>M</td>\n",
       "      <td>S</td>\n",
       "      <td>1982</td>\n",
       "      <td>37</td>\n",
       "      <td>35-39</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>30-39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>130513</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>611203</td>\n",
       "      <td>357</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2319.99</td>\n",
       "      <td>1962-08-07</td>\n",
       "      <td>M</td>\n",
       "      <td>M</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>&gt;=40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   sales_order_key create_date customer_key product_key english_product_name  \\\n",
       "4           130510  2019-11-01       314788         581    Road-350-W Yellow   \n",
       "5           130511  2019-11-01       515066         370         Road-250 Red   \n",
       "7           130513  2019-11-01       611203         357  Mountain-200 Silver   \n",
       "\n",
       "  cpzl_zw cplb_zw  unit_price  birth_date gender marital_status  birth_year  \\\n",
       "4   公路自行车     自行车     1700.99  1962-06-21      F              M        1962   \n",
       "5   公路自行车     自行车     2443.35  1982-10-17      M              S        1982   \n",
       "7   山地自行车     自行车     2319.99  1962-08-07      M              M        1962   \n",
       "\n",
       "   customer_age age_level  age_level_rate age_level2  \n",
       "4            57     55-59        0.000291       >=40  \n",
       "5            37     35-39        0.000291      30-39  \n",
       "7            57     55-59        0.000291       >=40  "
      ]
     },
     "execution_count": 201,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将年龄分为3个层次\n",
    "df_customer_order_bycle.loc[(df_customer_order_bycle['customer_age'] <= 29),'age_level2'] = '<=29'\n",
    "df_customer_order_bycle.loc[(df_customer_order_bycle['customer_age'] >= 30) & (df_customer_order_bycle['customer_age'] < 40),'age_level2'] = '30-39'\n",
    "df_customer_order_bycle.loc[(df_customer_order_bycle['customer_age'] >= 40),'age_level2'] = '>=40'\n",
    "\n",
    "df_customer_order_bycle.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3438"
      ]
     },
     "execution_count": 202,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df_customer_order_bycle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 求每个年龄段人数\n",
    "age_level2_count = df_customer_order_bycle.groupby(by = 'age_level2').sales_order_key.count().reset_index()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.2、用户性别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [],
   "source": [
    "gender_count = df_customer_order_bycle.groupby(by = 'gender').cplb_zw.count().reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gender</th>\n",
       "      <th>cplb_zw</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>F</td>\n",
       "      <td>1547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>M</td>\n",
       "      <td>1891</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  gender  cplb_zw\n",
       "0      F     1547\n",
       "1      M     1891"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gender_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_customer_order_bycle = pd.merge(df_customer_order_bycle,age_level2_count,on = 'age_level2').rename(columns = {'sales_order_key_y':'age_level2_count'})\n",
    "df_customer_order_bycle['age_level2_rate'] = 1/df_customer_order_bycle['age_level2_count']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sales_order_key_x</th>\n",
       "      <th>create_date</th>\n",
       "      <th>customer_key</th>\n",
       "      <th>product_key</th>\n",
       "      <th>english_product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw_x</th>\n",
       "      <th>unit_price</th>\n",
       "      <th>birth_date</th>\n",
       "      <th>gender</th>\n",
       "      <th>...</th>\n",
       "      <th>birth_year</th>\n",
       "      <th>customer_age</th>\n",
       "      <th>age_level</th>\n",
       "      <th>age_level_rate</th>\n",
       "      <th>age_level2</th>\n",
       "      <th>age_level2_count</th>\n",
       "      <th>age_level2_rate</th>\n",
       "      <th>gender_count</th>\n",
       "      <th>gender_rate</th>\n",
       "      <th>cplb_zw</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>130510</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>314788</td>\n",
       "      <td>581</td>\n",
       "      <td>Road-350-W Yellow</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1700.9900</td>\n",
       "      <td>1962-06-21</td>\n",
       "      <td>F</td>\n",
       "      <td>...</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>&gt;=40</td>\n",
       "      <td>2146</td>\n",
       "      <td>0.000466</td>\n",
       "      <td>1547</td>\n",
       "      <td>0.000646</td>\n",
       "      <td>1547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>130514</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>732668</td>\n",
       "      <td>354</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2071.4196</td>\n",
       "      <td>1964-10-21</td>\n",
       "      <td>F</td>\n",
       "      <td>...</td>\n",
       "      <td>1964</td>\n",
       "      <td>55</td>\n",
       "      <td>50-54</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>&gt;=40</td>\n",
       "      <td>2146</td>\n",
       "      <td>0.000466</td>\n",
       "      <td>1547</td>\n",
       "      <td>0.000646</td>\n",
       "      <td>1547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>130515</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>313465</td>\n",
       "      <td>363</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>2294.9900</td>\n",
       "      <td>1962-05-05</td>\n",
       "      <td>F</td>\n",
       "      <td>...</td>\n",
       "      <td>1962</td>\n",
       "      <td>57</td>\n",
       "      <td>55-59</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>&gt;=40</td>\n",
       "      <td>2146</td>\n",
       "      <td>0.000466</td>\n",
       "      <td>1547</td>\n",
       "      <td>0.000646</td>\n",
       "      <td>1547</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   sales_order_key_x create_date customer_key product_key  \\\n",
       "0             130510  2019-11-01       314788         581   \n",
       "1             130514  2019-11-01       732668         354   \n",
       "2             130515  2019-11-01       313465         363   \n",
       "\n",
       "  english_product_name cpzl_zw cplb_zw_x  unit_price  birth_date gender  \\\n",
       "0    Road-350-W Yellow   公路自行车       自行车   1700.9900  1962-06-21      F   \n",
       "1  Mountain-200 Silver   山地自行车       自行车   2071.4196  1964-10-21      F   \n",
       "2   Mountain-200 Black   山地自行车       自行车   2294.9900  1962-05-05      F   \n",
       "\n",
       "    ...    birth_year  customer_age  age_level age_level_rate  age_level2  \\\n",
       "0   ...          1962            57      55-59       0.000291        >=40   \n",
       "1   ...          1964            55      50-54       0.000291        >=40   \n",
       "2   ...          1962            57      55-59       0.000291        >=40   \n",
       "\n",
       "  age_level2_count  age_level2_rate  gender_count  gender_rate  cplb_zw  \n",
       "0             2146         0.000466          1547     0.000646     1547  \n",
       "1             2146         0.000466          1547     0.000646     1547  \n",
       "2             2146         0.000466          1547     0.000646     1547  \n",
       "\n",
       "[3 rows x 21 columns]"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_customer_order_bycle = pd.merge(df_customer_order_bycle,gender_count,on = 'gender').rename(columns = {'cplb_zw_y':'gender_count'})\n",
    "df_customer_order_bycle['gender_rate'] = 1/df_customer_order_bycle['gender_count']\n",
    "\n",
    "df_customer_order_bycle.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #df_customer_order_bycle 将11月自行车用户存入数据库\n",
    "# #存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/adventure_ods?charset=gbk')\n",
    "# datafrog=engine\n",
    "# df_customer_order_bycle.to_sql('pt_user_behavior_november',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 五、2019年11月热品销售分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_date</th>\n",
       "      <th>product_name</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>cplb_zw</th>\n",
       "      <th>order_num</th>\n",
       "      <th>customer_num</th>\n",
       "      <th>sum_amount</th>\n",
       "      <th>is_current_year</th>\n",
       "      <th>is_last_year</th>\n",
       "      <th>is_yesterday</th>\n",
       "      <th>is_today</th>\n",
       "      <th>is_current_month</th>\n",
       "      <th>is_current_quarter</th>\n",
       "      <th>chinese_province</th>\n",
       "      <th>chinese_city</th>\n",
       "      <th>chinese_territory</th>\n",
       "      <th>create_year_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>安徽省</td>\n",
       "      <td>马鞍山市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3399.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>西藏自治区</td>\n",
       "      <td>拉萨市</td>\n",
       "      <td>西南</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>2019-01-01</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>自行车</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2294.99</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济南市</td>\n",
       "      <td>华东</td>\n",
       "      <td>201901</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_date         product_name cpzl_zw cplb_zw  order_num  customer_num  \\\n",
       "150  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "151  2019-01-01  Mountain-100 Silver   山地自行车     自行车          1             1   \n",
       "152  2019-01-01   Mountain-200 Black   山地自行车     自行车          1             1   \n",
       "\n",
       "     sum_amount is_current_year is_last_year is_yesterday is_today  \\\n",
       "150     3399.99               0            1            0        0   \n",
       "151     3399.99               0            1            0        0   \n",
       "152     2294.99               0            1            0        0   \n",
       "\n",
       "    is_current_month is_current_quarter chinese_province chinese_city  \\\n",
       "150                0                  0              安徽省         马鞍山市   \n",
       "151                0                  0            西藏自治区          拉萨市   \n",
       "152                0                  0              山东省          济南市   \n",
       "\n",
       "    chinese_territory  create_year_month  \n",
       "150                华东             201901  \n",
       "151                西南             201901  \n",
       "152                华东             201901  "
      ]
     },
     "execution_count": 211,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#gather_customer_order在分析自行车整体表现得时已从数据库导入表（ dw_customer_order），并筛选仅自行车数据，这里不再导入\n",
    "gather_customer_order.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.1、11月产品销量TOP10产品，销售数量及环比\n",
    "\n",
    "我们在分析“2019年11月自行车产品销售表现”时已计算出11月所有产品的销量及环比，这里不在重复计算，直接使用gather_customer_order_month_10_11、gather_customer_order_month_11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [],
   "source": [
    "#筛选11月数据\n",
    "gather_customer_order_11 = gather_customer_order.loc[gather_customer_order['create_year_month'] == 201911]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**计算TOP10产品**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {},
   "outputs": [],
   "source": [
    "#计算产品销售数量,\\ 为换行符\n",
    "#按照销量降序，取TOP10产品\n",
    "\n",
    "customer_order_11_top10 = gather_customer_order_11.groupby(by = 'product_name').order_num.count().reset_index().\\\n",
    "                        sort_values(by = 'order_num',ascending = False).head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>385</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Road-150 Red</td>\n",
       "      <td>339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Road-750 Black</td>\n",
       "      <td>304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Road-550-W Yellow</td>\n",
       "      <td>289</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           product_name  order_num\n",
       "3   Mountain-200 Silver        385\n",
       "2    Mountain-200 Black        360\n",
       "7          Road-150 Red        339\n",
       "14       Road-750 Black        304\n",
       "11    Road-550-W Yellow        289"
      ]
     },
     "execution_count": 215,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_order_11_top10.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mountain-200 Silver',\n",
       " 'Mountain-200 Black',\n",
       " 'Road-150 Red',\n",
       " 'Road-750 Black',\n",
       " 'Road-550-W Yellow',\n",
       " 'Road-250 Black',\n",
       " 'Road-350-W Yellow',\n",
       " 'Road-250 Red',\n",
       " 'Touring-1000 Blue',\n",
       " 'Mountain-400-W Silver']"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#TOP10销量产品信息\n",
    "list(customer_order_11_top10['product_name'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**计算TOP10销量及环比**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "      <th>order_num_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>42</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.040856</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045956</td>\n",
       "      <td>0.190476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>31</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.030156</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>36</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.033088</td>\n",
       "      <td>0.161290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>379</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1028</td>\n",
       "      <td>0.368677</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "63             201910   Mountain-100 Black                   42   山地自行车   \n",
       "70             201911   Mountain-100 Black                   50   山地自行车   \n",
       "64             201910  Mountain-100 Silver                   31   山地自行车   \n",
       "71             201911  Mountain-100 Silver                   36   山地自行车   \n",
       "65             201910   Mountain-200 Black                  379   山地自行车   \n",
       "\n",
       "    sum_order_month  order_num_proportio  order_num_diff  \n",
       "63             1028             0.040856        0.000000  \n",
       "70             1088             0.045956        0.190476  \n",
       "64             1028             0.030156        0.000000  \n",
       "71             1088             0.033088        0.161290  \n",
       "65             1028             0.368677        0.000000  "
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查看11月环比数据\n",
    "gather_customer_order_month_10_11.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里我们只需要四个字段：create_year_month月份，product_name产品名，order_month_product本月销量，cpzl_zw产品类别，\n",
    "\n",
    "order_num_diff本月产品销量环比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_order_month_10_11 = gather_customer_order_month_10_11[['create_year_month','product_name','order_month_product','cpzl_zw','order_num_diff']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_order_month_10_11 = customer_order_month_10_11[customer_order_month_10_11['product_name'].\\\n",
    "                                                        isin(list(customer_order_11_top10['product_name']))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_order_month_10_11['category'] = '本月TOP10销量'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>order_num_diff</th>\n",
       "      <th>category</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>379</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10销量</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-200 Black</td>\n",
       "      <td>374</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>-0.013193</td>\n",
       "      <td>本月TOP10销量</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>357</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10销量</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-200 Silver</td>\n",
       "      <td>395</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.106443</td>\n",
       "      <td>本月TOP10销量</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-400-W Silver</td>\n",
       "      <td>126</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10销量</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month           product_name  order_month_product cpzl_zw  \\\n",
       "65             201910     Mountain-200 Black                  379   山地自行车   \n",
       "72             201911     Mountain-200 Black                  374   山地自行车   \n",
       "66             201910    Mountain-200 Silver                  357   山地自行车   \n",
       "73             201911    Mountain-200 Silver                  395   山地自行车   \n",
       "67             201910  Mountain-400-W Silver                  126   山地自行车   \n",
       "\n",
       "    order_num_diff   category  \n",
       "65        0.000000  本月TOP10销量  \n",
       "72       -0.013193  本月TOP10销量  \n",
       "66        0.000000  本月TOP10销量  \n",
       "73        0.106443  本月TOP10销量  \n",
       "67        0.000000  本月TOP10销量  "
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_order_month_10_11.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2、11月增速TOP10产品，销售数量及环比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_order_month_11 = gather_customer_order_month_10_11.loc[gather_customer_order_month_10_11['create_year_month'] == 201911].\\\n",
    "                            sort_values(by = 'order_num_diff',ascending = False).head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>sum_order_month</th>\n",
       "      <th>order_num_proportio</th>\n",
       "      <th>order_num_diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>201911</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>131</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>450</td>\n",
       "      <td>0.291111</td>\n",
       "      <td>0.284314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>201911</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>147</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>450</td>\n",
       "      <td>0.326667</td>\n",
       "      <td>0.235294</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-500 Silver</td>\n",
       "      <td>49</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045037</td>\n",
       "      <td>0.195122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.045956</td>\n",
       "      <td>0.190476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>36</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>1088</td>\n",
       "      <td>0.033088</td>\n",
       "      <td>0.161290</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "51             201911  Touring-1000 Yellow                  131   旅游自行车   \n",
       "50             201911    Touring-1000 Blue                  147   旅游自行车   \n",
       "76             201911  Mountain-500 Silver                   49   山地自行车   \n",
       "70             201911   Mountain-100 Black                   50   山地自行车   \n",
       "71             201911  Mountain-100 Silver                   36   山地自行车   \n",
       "\n",
       "    sum_order_month  order_num_proportio  order_num_diff  \n",
       "51              450             0.291111        0.284314  \n",
       "50              450             0.326667        0.235294  \n",
       "76             1088             0.045037        0.195122  \n",
       "70             1088             0.045956        0.190476  \n",
       "71             1088             0.033088        0.161290  "
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_order_month_11.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_order_month_11_top10_seep = gather_customer_order_month_10_11.loc[gather_customer_order_month_10_11['product_name'].\\\n",
    "                                                        isin(list(customer_order_month_11['product_name']))]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "筛选我们需要的四个字段：create_year_month月份，product_name产品名，order_month_product本月销量，cpzl_zw产品类别，\n",
    "\n",
    "order_num_diff本月产品销量环比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_order_month_11_top10_seep = customer_order_month_11_top10_seep[['create_year_month','product_name','order_month_product','cpzl_zw','order_num_diff']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_order_month_11_top10_seep['category'] = '本月TOP10增速'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>order_num_diff</th>\n",
       "      <th>category</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>42</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Black</td>\n",
       "      <td>50</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.190476</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>31</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>201911</td>\n",
       "      <td>Mountain-100 Silver</td>\n",
       "      <td>36</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.161290</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>201910</td>\n",
       "      <td>Mountain-500 Silver</td>\n",
       "      <td>41</td>\n",
       "      <td>山地自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "63             201910   Mountain-100 Black                   42   山地自行车   \n",
       "70             201911   Mountain-100 Black                   50   山地自行车   \n",
       "64             201910  Mountain-100 Silver                   31   山地自行车   \n",
       "71             201911  Mountain-100 Silver                   36   山地自行车   \n",
       "69             201910  Mountain-500 Silver                   41   山地自行车   \n",
       "\n",
       "    order_num_diff   category  \n",
       "63        0.000000  本月TOP10增速  \n",
       "70        0.190476  本月TOP10增速  \n",
       "64        0.000000  本月TOP10增速  \n",
       "71        0.161290  本月TOP10增速  \n",
       "69        0.000000  本月TOP10增速  "
      ]
     },
     "execution_count": 228,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_order_month_11_top10_seep.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**合并TOP10销量表customer_order_month_10_11，TOP10增速customer_order_month_11_top10_seep**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "metadata": {},
   "outputs": [],
   "source": [
    "#axis = 0按照行维度合并，axis = 1按照列维度合并\n",
    "hot_products_11 = pd.concat([customer_order_month_10_11,customer_order_month_11_top10_seep],axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>create_year_month</th>\n",
       "      <th>product_name</th>\n",
       "      <th>order_month_product</th>\n",
       "      <th>cpzl_zw</th>\n",
       "      <th>order_num_diff</th>\n",
       "      <th>category</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>201911</td>\n",
       "      <td>Road-650 Red</td>\n",
       "      <td>103</td>\n",
       "      <td>公路自行车</td>\n",
       "      <td>0.131868</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>201910</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>119</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>201911</td>\n",
       "      <td>Touring-1000 Blue</td>\n",
       "      <td>147</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>0.235294</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>201910</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>102</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>201911</td>\n",
       "      <td>Touring-1000 Yellow</td>\n",
       "      <td>131</td>\n",
       "      <td>旅游自行车</td>\n",
       "      <td>0.284314</td>\n",
       "      <td>本月TOP10增速</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    create_year_month         product_name  order_month_product cpzl_zw  \\\n",
       "86             201911         Road-650 Red                  103   公路自行车   \n",
       "45             201910    Touring-1000 Blue                  119   旅游自行车   \n",
       "50             201911    Touring-1000 Blue                  147   旅游自行车   \n",
       "46             201910  Touring-1000 Yellow                  102   旅游自行车   \n",
       "51             201911  Touring-1000 Yellow                  131   旅游自行车   \n",
       "\n",
       "    order_num_diff   category  \n",
       "86        0.131868  本月TOP10增速  \n",
       "45        0.000000  本月TOP10增速  \n",
       "50        0.235294  本月TOP10增速  \n",
       "46        0.000000  本月TOP10增速  \n",
       "51        0.284314  本月TOP10增速  "
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hot_products_11.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字段注释：\n",
    "\n",
    "create_year_month：月份，product_name：产品名，order_month_product：本月产品销量，order_num_diff：本月产品环比，category：分类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #存入数据库\n",
    "# engine = create_engine('mysql://root:FrogMysql123!@106.15.121.232:3306/adventure_ods?charset=gbk')\n",
    "# datafrog=engine\n",
    "# hot_products_11.to_sql('pt_hot_products_november',con = datafrog,if_exists='append', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
